I am new to MySQLi and following some examples. I am unclear as to why the function data_seek() is being used here in the for loop. If I'm not mistaken, it returns true/ false depending on if there is data in the current row passed to it. I'm only confused because the code runs fine without it, so it appears. Here is the example:
<?php
require_once 'login.php';
$connection = new mysqli($db_hostname, $db_username, $db_password, $db_database);
if($connection->connect_error) die("Connection error: " . $connection->connect_error);
$query = "SELECT * FROM classics";
$result = $connection->query($query);
if(!$result) die($connection->error);
$rows = $result->num_rows;
for($i =0; $i < $rows; ++$i)
{
$result->data_seek($i); ///////////////////Why is this here?
$row = $result->fetch_array(MYSQLI_ASSOC);
echo 'Author: ' .$row['author'] .'<br>';
echo 'Title: ' .$row['title'] .'<br>';
echo 'Category: ' .$row['category'] .'<br>';
echo 'Year: ' .$row['year'] .'<br>';
echo 'ISBN: ' .$row['isbn'] .'<br><br>';
}
$result->close();
$connection->close();
?>