If you have already register Login here.
Show records using mysql_fetch_row( ) function
mysql_fetch_row() function returns a row from a recordset as a numeric array. mysqli_fetch_row() return a single row from the number of records available in the database. at a time it return only the first row of the result set. if we want to retrieve all the rows of the table then we must put this function inside the while loop.
mysql_fetch_row(query)
<?php
$host = "localhost";
$user = "";
$pass = "";
$dbname = "users";
$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
if(!$conn){
die("Could not connect:".mysql_connect_error());
}
// select database
mysql_select_db($dbname,$conn);
$sql = "SELECT * FROM users";
$result=mysql_query($sql);
print_r(mysql_fetch_row($result));
mysql_close();
?>
Array(
[0] =>1
[1] => rakesh
[2] =>20000
)
<?php
$host = "localhost";
$user = "";
$pass = "";
$dbname = "users";
$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
if(!$conn){
die("Could not connect:".mysql_connect_error());
}
// select database
mysql_select_db($dbname,$conn);
$sql = "SELECT * FROM users";
$retval=mysql_query($sql);
if(mysql_num_rows($retval) > 0){
echo "<table border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>Salary</th></tr>";
while($row= mysql_fetch_row($retval))
{
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "</tr>";
}
echo "</table>";
}else{
echo "0 results";
}
mysql_close();
?>
id | name | salary |
---|---|---|
1 | Name1 | 55000 |
2 | Name2 | 70000 |
© 2025 Easy To Learning. All Rights Reserved | Design by Easy To Learning