I have the following code:
include $_SERVER['DOCUMENT_ROOT'].'/include/conn.php';
$query = "SELECT title FROM news_event";
$result = $mysqli->query($query);
$row = $result->fetch_array(MYSQLI_BOTH);
$row_cnt = $result->num_rows;
$result->free();
$mysqli->close();
This is fine if there is only one result as I can just echo $row['title']
but if there are lots of results, how do I get this to loop through and print every row?
I'm sure this is really simple but I'm just not sure what I need to search for in Google.
I'm looking for a mysqli
equivalent of this:
while( $row = mysql_fetch_array($result) )
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
Just replace it with mysqli_fetch_array
or mysqli_result::fetch_array
:)
while( $row = $result->fetch_array() )
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />";
}
Almost all mysql_*
functions have a corresponding mysqli_*
function.
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