xxxxxxxxxx
* The fetch_assoc() / mysqli_fetch_assoc() function fetches a result row as an associative array.
Note: Fieldnames returned from this function are case-sensitive.
mysqli_fetch_assoc(result)
How does while loop work with mysqli_fetch_assoc()?
xxxxxxxxxx
$sql = "SELECT name FROM table1";
$result = mysqli_query($conn, $sql);
if($result){
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
echo "Name: " . $row["name"]. "<br>";
}
}
}
xxxxxxxxxx
$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
$result = mysqli_query($con, $sql);
/*MYSQLI_ASSOC
MYSQLI_NUM (this is default)
MYSQLI_BOTH
*/
// Fetch all
mysqli_fetch_all($result, MYSQLI_ASSOC);
xxxxxxxxxx
mysqli_fetch_assoc()
/*its used to return associative array representing the next row in the result
set for the result represented by the result parameter*/