Note that there are some explanatory texts on larger screens.

plurals
  1. POPagination using MySQL LIMIT, OFFSET
    primarykey
    data
    text
    <p>I have some code that LIMITs data to display only 4 items per page. The column I'm using has about 20-30 items, so I need to make those spread out across the pages. </p> <p>On the first page, I have:</p> <pre><code> $result = mysqli_query($con,"SELECT * FROM menuitem LIMIT 4"); { echo "&lt;tr&gt;"; echo "&lt;td align='center'&gt;&lt;img src=\"" . $row['picturepath'] . "\" /&gt;&lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $row['name'] . "&lt;/td&gt; &lt;td align='center'&gt; &lt;input type='button' value='More Info'; onclick=\"window.location='more_info.php?';\"&gt; &lt;/td&gt;"; echo "&lt;td align='center'&gt;" . $row['price'] . "&lt;/td&gt; &lt;td align='center'&gt; &lt;input type='button' value='Add to Order' onclick=''&gt; &lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; mysqli_close($con); ?&gt; &lt;table width="1024" align="center" &gt; &lt;tr height="50"&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td width="80%" align="right"&gt; &lt;a href="itempage2.php"&gt;NEXT&lt;/a&gt; &lt;/td&gt; &lt;td width="20%" align="right"&gt; &lt;a href=""&gt;MAIN MENU&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>You'll notice towards the bottom of the page my anchor tag within lists the second page, "itempage2.php". In item page 2, I have the same code, except my select statement lists the offset of 4.</p> <pre><code>$result = mysqli_query($con,"SELECT * FROM menuitem LIMIT 4 offset 4"); </code></pre> <p>This works, this way when there is a pre-determined number of items within my database. But it's not that good. I need to create a new page only if there are more items, not hard-coded into it like it is now. </p> <p>How can I create multiple pages without having to hard-code each new page, and offset?</p>
    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.
 

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