title: PHP Pagination is Getting the Error: Incorrect syntax near 'LIMIT'. (severity 15) When Connecting to MSSQL DB
body: <p>My PHP page is supposed to display a MSSQL table's rows 4 rows a page. After four rows have been displayed the next four will be displayed on a newly created page with a link on the previous page to grant access to it. This code has been worked with MySQL with some edits, of course. I suppose the error is from the $sql code, but I don't know exactly what is causing it. When I run my PHP page on the website, I appear to be getting the errors </p>
  
  <pre><code>Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'LIMIT'. (severity 15) in D:\Hosting\4502990\html\sales\usedunits.php on line 8
  
  Warning: mssql_query() [function.mssql-query]: Query failed in D:\Hosting\4502990\html\sales\usedunits.php on line 8
  Incorrect syntax near 'LIMIT'.
  </code></pre>
  
  <p>Here is my full PHP page's code:</p>
  
  <pre><code>&lt;?php 
  if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
  // connect to db
  $connection = mssql_connect('gbam','GBaer','dsa!');
  mssql_select_db('asdr',$connection);
  $start_from = ($page-1) * 4; 
  $sql = "SELECT * FROM used_trailers1 ORDER BY orderid ASC LIMIT '$start_from',4";
  $rs_result = mssql_query ($sql, $connection); 
  echo mssql_get_last_message( $connection );
  ?&gt;
  &lt;!doctype html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" media="screen" href="css/mobilemenu.css"/&gt;
  &lt;script src="respond.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
    ga('create', 'UA-45342007-3', 'gba.ca');
    ga('send', 'pageview');
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body bgcolor="#102540"&gt;
  &lt;div class="gridContainer clearfix"&gt;
    &lt;div id="div1" class="fluid"&gt;
      &lt;div id="navcontain"&gt;&lt;/div&gt;
  
    &lt;div id="wrapper"&gt;
      &lt;div id="cover"&gt;&lt;/div&gt;
    &lt;div id="mainnaviphone"&gt;
      &lt;a href="../index.html"&gt;&lt;img id="logo" src="images/gbmlogo.jpg" alt="G.B.M. Trailer Service LTD. Logo" title="G.B.M. Trailer Service LTD. Logo"/&gt;&lt;/a&gt;
      &lt;img src="images/newunitsbutton.png" alt="New Units Button" title="New Units Button" id="buto1"&gt;
    &lt;img src="images/usedunitsbutton.png" alt="Used Units Button" title="Used Units Button" id="buto2"&gt;
    &lt;a href="../index.html"&gt;&lt;img src="images/homebutton.png" alt="home" title="Home" id="homebuto"/&gt;&lt;/a&gt;
    &lt;a href="#"&gt;&lt;img src="images/previousbutton.png" alt="previous" title="Previous" id="prevbuto"/&gt;&lt;/a&gt;
    &lt;a href="#"&gt;&lt;img src="images/nextbutton.png" alt="next" title="Next" id="nextbuto"/&gt;&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;div id="background2"&gt;
  &lt;div id="textcontrol"&gt;
  
  &lt;?php 
  while ($row = mssql_fetch_assoc($rs_result)) { 
  ?&gt; 
  &lt;div id='used1'&gt;
  &lt;div id='rigtitle' class="contentHolder Default"&gt;
  &lt;? echo $row["title"]; ?&gt;
  &lt;/div&gt;
  &lt;table class="infotabe1"&gt;&lt;tr&gt;&lt;td class="desctde"&gt;Description: &lt;/td&gt;&lt;td rowspan="2" id="content_1" class="infotde contentHolder Default"&gt;&lt;? echo $row["description"]; ?&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;table class="infotabe"&gt;&lt;tr&gt;&lt;td class="desctd"&gt;Make: &lt;/td&gt;&lt;td id="content_1" class="infotd contentHolder Default"&gt;&lt;? echo $row["make"]; ?&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;table class="infotabe"&gt;&lt;tr&gt;&lt;td class="desctd"&gt;Model: &lt;/td&gt;&lt;td id="content_1" class="infotd contentHolder Default"&gt;&lt;? echo $row["model"]; ?&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;table class="infotabe"&gt;&lt;tr&gt;&lt;td class="desctd"&gt;Year: &lt;/td&gt;&lt;td id="content_1" class="infotd contentHolder Default"&gt;&lt;? echo $row["year"]; ?&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  &lt;table class="infotabe"&gt;&lt;tr&gt;&lt;td class="desctd"&gt;Price: &lt;/td&gt;&lt;td id="content_1" class="infotd contentHolder Default"&gt;&lt;? echo $row["price"]; ?&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
  
  &lt;!-- Unit Picture --&gt;
  &lt;img src='images/&lt;? echo $row["photo"]; ?&gt;' id='mainimage'&gt;
  &lt;a href='usedunit.php?orderid=&lt;? echo $row["orderid"]; ?&gt;'&gt;&lt;img src='images/picturesandspecsbutton.png' alt='Pictures and Specs' title='Pictures and Specs' id='picsandspecsbuto'&gt;&lt;/a&gt;
  &lt;/div&gt;
  &lt;?php 
  }; 
  ?&gt;
  &lt;/div&gt;
  &lt;div id="description" class="resize"&gt;
    &lt;p&gt;&lt;u&gt;Click&lt;/u&gt; or call for more information or enquiries.&lt;/p&gt;
  &lt;/div&gt;
  &lt;div id="bottomquote"&gt;
    Your Certified Tanker Trailer Specialist
  &lt;/div&gt;
  &lt;div id="bottomcontactinfo"&gt;
    &lt;em&gt;Phone &lt;a style="color:white; text-decoration:none;" href="tel:1-4032799717"&gt;403 279 9717&lt;/a&gt; or &lt;a style="color:white; text-decoration:none;" href="tel:1-888-426-9717"&gt;1 888 426 9717&lt;/a&gt; 9300 Endeavor Dr. SE, Calgary Alberta, T3S 0A1&lt;br /&gt;&lt;a style="color:white; text-decoration:none;" href="mailto:info@gar.ca"&gt;info@galer.ca&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;img src="images/visamastercardlogos.gif" id="visamastercardlogos" alt="Visa and Mastercard Logo" title="Visa and Mastercard Logo"&gt;
  
  &lt;a href="#"&gt;&lt;img id="mycart" src="images/mycart.gif" alt="My Cart" title="My Cart"&gt;&lt;/a&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  &lt;!--
  var autoSizeText;
  autoSizeText = function() {
    var el, elements, _i, _len, _results;
    elements = $('.resize');
    console.log(elements);
    if (elements.length &lt; 0) {
      return;
    }
    _results = [];
    for (_i = 0, _len = elements.length; _i &lt; _len; _i++) {
      el = elements[_i];
      _results.push((function(el) {
        var resizeText, _results1;
        resizeText = function() {
          var elNewFontSize;
          elNewFontSize = (parseInt($(el).css('font-size').slice(0, -2)) - 1) + 'px';
          return $(el).css('font-size', elNewFontSize);
        };
        _results1 = [];
        while (el.scrollHeight &gt; el.offsetHeight) {
          _results1.push(resizeText());
        }
        return _results1;
      })(el));
    }
    return _results;
  };
  
  autoSizeText(); // here is where we call the function.
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php 
  $sql = "SELECT COUNT(orderid) FROM used_trailers1";
  $rs_result = mssql_query($sql, $connection); 
  $row = mssql_fetch_row($rs_result); 
  $total_records = $row[0]; 
  $total_pages = ceil($total_records / 4); 
  
  $sqlef = 'SELECT * FROM used_trailers1';
  $rs_resultt = mssql_query($sqlef, $connection); 
  $rowcount = mssql_num_rows($rs_resultt);
  
  $record_start = $start_from + 1;
  $record_end   = $record_start + 3;
  
  // Remember to check against the max record
  if ($record_end &gt; $total_records) {
     $record_end = $total_records;
  }
  
      echo "Showing ".$record_start." - ".$record_end." of ".$rowcount." results ";
      echo "asd&lt;a href='usedunits.php?page=".$i."'&gt;".$i."&lt;/a&gt;";
  for ($i=1; $i&lt;=$total_pages; $i++) { 
              echo "&lt;a href='usedunits.php?page=".$i."'&gt;".$i."&lt;/a&gt; "; 
  }; 
  ?&gt;
  </code></pre>
  
  <p>I have changed the code to <code>$sql = "SELECT TOP $start_from * FROM used_trailers1 ORDER BY orderid";</code>. I know this is not what I am looking for because on page 1 it has 0 rows displayed. On page two it has 4 rows displayed, and on page three it has 8 rows displayed. Is there a way I can add max limit of 4 in there?</p>
  
  <p>Thank you for any help. All help is appreciated.</p>