MySQLI Fetch Row

Fetches a row from the result which was obtained from a mysql table.

Syntax:

mysqli_fetch_row(result) ;

 

Example:

1. Create a Connection

 

<?php 
$hostname = "localhost";
$username = "username";
$password = "password";
$database="database_name"; $db_connection=mysqli_connect($hostname,$username,$password,$database); ?>

2. Create a query and perform it.

<?php 
$database_query = "SELECT * from products WHERE price=400";
?>

3. Use the result

<?php 
while ($result_use=mysqli_fetch_row($result)) {
var_dump($result_use);
} ?>

4. Close the connection

<?php 
mysqli_close($db_connection);
 ?>

example

<?php
//1. Create a connection
$hostname = "localhost";
$username = "root";
$password = "password";
$database = "test";
$db_connection=mysqli_connect(
$hostname,$username,$password,$database
);
if (mysqli_connect_errno())
{
die('Connection to database failed');
}
?>

2. Create Database Query and perform it.

<?php
//2. Database Query
$database_query = "SELECT";
$database_query .= "* FROM products";
$records=mysqli_query($db_connection, $database_query);
if (!$records){die('query failed');}
?>
3. Use the returned Records for display.

<?php
//3. Use the returned records
$NumC=mysqli_num_fields($records);//Number of columns
echo "<ul>";
while($row=mysqli_fetch_row($records)){
echo "<li>";
for ($i=0;$i<$NumC;$i++){echo " ".$row[$i] .
" " ;}
echo "</li>";
}
echo "</ul>";
?>
4. Release the data.

<?php
//4. Free the data
mysqli_free_result($records);
?>
5. Close the connection.

<?php
//5. Close the connection
mysqli_close($db_connection);
?>