Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, first you need to find out the total number of records. Then run the query again, this time with a LIMIT at the end of your query. For example LIMIT 0, 10. This example returns 10 results starting with record 0 (the first record). If you dynamically set the first record of the limit results using a variable, you can have it update it with every page. For each page you can calculate what you want the starting record to be. For example, $offset= $recordsperpage * page number. </p> <p>I'm not sure exactly what your variables are, so I won't toy with your script. Here's an example I had used for a project that I know works. Example script: </p> <pre><code>//Use mysqli object instead of mysql_xxx, better security $db3= new mysqli($hostname, $username, $password, $dbname); //how many records I want per page $perPage= 9; //I'm passing the startrecording as a Get variable in the page links if($_GET['startingrecord']){ $startingRecord=trim($_GET['startingrecord']); } //but if there is no get variable, start at record zero else { $startingRecord=0; } //prepare your query $stmt3 = $db3-&gt;prepare("SELECT DISTINCT file, category, P.productID, price, title, price * (1- sale) FROM Products AS P INNER JOIN OrderProducts AS OP ON P.productID NOT IN (Select productID from OrderProducts) Left JOIN Sale AS S on P.productID= S.ProductID ORDER BY productID DESC"); // You can bind parameters if necessary, but it's not here //execute the query and store the result $stmt3 -&gt; execute(); $stmt3-&gt;store_result(); //determine the number of total rows $numberRows= $stmt3-&gt;num_rows; //close the db $db3 -&gt; close; //Reopen with limits this time. $db3= new mysqli($hostname, $username, $password, $dbname); $stmt3 = $db3-&gt;prepare("SELECT DISTINCT file, category, P.productID, price, title, price * (1- sale) FROM Products AS P INNER JOIN OrderProducts AS OP ON P.productID NOT IN (Select productID from OrderProducts) Left JOIN Sale AS S on P.productID= S.ProductID ORDER BY productID DESC LIMIT ?, ?"); // bind the startingrecord from the get variable and the perpage variable. stmt3-&gt;bind_param("ii", $startingRecord, $perPage); //you use ceiling to make sure if that if there's a remainder, you have an extra page for the stray results $pages= ceil($numberRows/ $perPage); //This is me generating the page links for ($i=1; $i&lt;= $pages; $i++) { if ($i==1){ $start=0; } else{ $start= ($i-1) * ($perPage); } echo "&lt;a href='#' onclick='gallery(\"startingrecord=".$start."\")'&gt;".$i." &lt;/a&gt;"; } $stmt3 -&gt; execute(); $stmt3-&gt;store_result(); $stmt3-&gt;bind_result($file, $category2, $productID, $price, $title2, $sale); while($stmt3-&gt;fetch()){ // do whatever you want to your result }) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload