What are some different ways to loop through a mysql result set? I'm new to PHP and MySQL so I'm looking for simple ways to loop through and an explanation as to how the provided code works.
the first example that comes to my mind:
<?php
$link = mysql_connect(/*arguments here*/);
$query = sprintf("select * from table");
$result = mysql_query($query, $link);
if ($result) {
while($row = mysql_fetch_array($result)) {
// do something with the $row
}
}
else {
echo mysql_error();
}
?>
Here is a full example:
http://php.net/manual/en/mysqli-result.fetch-array.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With