Skip to content Skip to sidebar Skip to footer

While Loop Using Php With A Mysql Server

I have a database (SQL) with the table 'Staff' with two records in it. I am required to display the contents of these records on a web page using PHP. <

Solution 1:

mysql_fetch_array() only retrieves a single row from the database. You need to call it inside your while loop to retrieve all rows. The $looping increment is unnecessary here, since mysql_fetch_array() returns false when no more rows are available.

while ($row = mysql_fetch_array($result))  
{
    echo$row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
}

Solution 2:

I'll do...

while ($row = mysql_fetch_assoc($result)) {
   //print $row;
}

Solution 3:

while ($row = mysql_fetch_array($result))  
    {
        echo$row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
    }

Solution 4:

<?php$qry = mysql_query($result); 
while ($row = mysql_fetch_array($qry))  
    {
        echo$row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
    }
?>

Solution 5:

PHP has great documentation with examples. Check out the example for mysql_fetch_array().

Your code should look like this:

<?phpwhile($row = mysql_fetch_array($result)) {
     echo$row["Name"].", Room ".$row["Room"].", Tel ".$row["Telephone"] ;
  }
?>

Post a Comment for "While Loop Using Php With A Mysql Server"