PHP mysqli_fetch_assoc() function is used to fetch results row as an associative.
Syntax
array mysqli_fetch_assoc(result);
Parameter | Description |
---|---|
result : | Required parameter. Mention a result set identifier returned by mysqli_query(). |
Return Values : | Returns an associative array of strings that corresponds to the fetched row, or FALSE if there are no more rows. |
<?php $con = mysqli_fetch_assoct("localhost","user","password","db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "SELECT fname, lname FROM employee"; $sql_result = mysqli_query($con, $sql); while ($row = mysqli_fetch_assoc($sql_result)) { echo "First Name : ". $row["fname"] . " Last Name : ". $row["lname"]; } mysql_free_result($sql_result); mysqli_close($con); ?>