Echo DB table starting at primary key id
-
I am using code from https://www.w3schools.com/php/php_mysql_select.asp to pull data from a custom DB table. The above code works great but it returns ALL database rows. I have added a form element so they can enter a number. The code needs to return all rows starting at that number. So if there were 1000 rows they could enter 900 and it would start at row number 900 and show all rows after that – so rows 900 thru 1000. Here is where I’m at:
if($_GET[‘submitted’]){
$servername = “123.4.5.6.7.8.9.0”;
$username = “someusername”;
$password = “somepassword”;
$dbname = “somedbname”;
$startat = $_GET[‘StartRecords’]; // form input number to start returning results// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}$sql = “SELECT pkid, cn, in, fn, em, ph, ad1, ad2, ha, hb, ci, cd FROM some_table_name WHERE pkid = $startat”; // pkid = primary key id
$result = $conn->query($sql);if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo “<tr>”;
echo “<td>” . $row[‘pkid’] . “</td>”;
echo “<td>” . $row[‘cn’] . “</td>”;
echo “<td>” . $row[‘in’] . “</td>”;
echo “<td>” . $row[‘fn’] . “</td>”;
echo “<td>” . $row[’em’] . “</td>”;
echo “<td>” . $row[‘ph’] . “</td>”;
echo “<td>” . $row[‘ad1’] . “</td>”;
echo “<td>” . $row[‘ad2’] . “</td>”;
echo “<td>” . $row[‘ha’] . “</td>”;
echo “<td>” . $row[‘hb’] . “</td>”;
echo “<td>” . $row[‘ci’] . “</td>”;
echo “<td>” . $row[‘cd’] . “</td>”;
echo “</tr>”;
}
} else {
echo “<tr><td colspan=’12’>Your query returned 0 results. Try entering a lower number.</td></tr>”;
}
$conn->close();
}What this code does is shows ONLY the row pkid that matches and nothing after that – so it only returns on row of information. I want it to return the row matching the pkid and all rows after too.
Ideas?
- The topic ‘Echo DB table starting at primary key id’ is closed to new replies.