Hi all, im trying to manipulate a table from sql database via php.. i have managed to return the data and now my question is how do i limit that data to say 25 records.. and then have the option to go to next 25 rows and back? Here is my current code this returns the table with the data (but all of it) so will continue if more then 25 rows etc.. include('db_connect.php'); $sql = "SELECT * FROM `records`"; $result = mysql_query($sql); echo "<table border='1' padding='2'> <tr> <th>ID</th> <th>Test</th> <th>Test 2</th> <th>Test 3</th> <th>Test 4</th> <th>Test 5</th> <th>Test 6</th> <th>Test 7</th> <th>Test 8</th> <th>Test 9</th> <th>Test 10</th> </tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['Test 1'] . "</td>"; echo "<td>" . $row['Test 2'] . "</td>"; echo "<td>£" . $row['Test 3'] . "</td>"; echo "<td>£" . $row['Test 4'] . "</td>"; echo "<td>£" . $row['Test 5'] . "</td>"; echo "<td>£" . $row['Test 6'] . "</td>"; echo "<td>£" . $row['Test 7'] . "</td>"; echo "<td>" . $row['Test 8'] . "</td>"; echo "<td>" . $row['Test 9'] . "</td>"; echo "<td>£" . $row['Test 10'] . "</td>"; echo "</tr>"; } echo "</table>"; PHP: Thats my current code.. it connects and returns all records what's the best way to return 25 of the records and then be able to filter forward and back (per 25) thanks, Matt
You will need to use offset in your query (either with offset itself or part of your limit). Just calculate the number of queries to skip based upon paging. domain.com/interesting_date/?page=2 Code (markup): So then you would know you need to skip 25 records. $offset = ($page_number - 1) * 25; $limit = 25; Code (markup): Then your query would be: SELECT useful_names FROM useful_table WHERE useful = "yes" LIMIT $limit,$offset; Code (markup): Or: SELECT useful_names FROM useful_table WHERE useful = "yes" LIMIT $limit OFFSET $offset; Code (markup):