Reputation: 417
Hello everyone
I bring forth the following issue: My php code skips the first mysql row when printing it onto the screen. I have already seen that the issue is solved by removing a double fetch() method outside the while() loop on other questions, but I fail to see that happening here, so what else could it be? Im lost.
This is the code:
<?php
$servername = "localhost";
$username = "root";
$password = "standup";
$database = "sakila";
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully<br><br>";
$query = "select * from actor;";
$queryResult = $conn->query($query);
while($queryRow = $queryResult->fetch_row()){
echo "$queryRow[1]<br>";
}
$conn->close();
?>
This is the original database:
And this is the result in a browser
Upvotes: 1
Views: 88
Reputation: 417
Solution 1
Add order by
to the query, in this situation $query = "select * from actor order by actor_id;";
solved the issue of skipping the first row.
Solution 2
Add limit
to the query, in this situation $query = "select * from actor limit 100;";
solved the issue of skipping the first row also.
Upvotes: 2