Retrieve data from MySQL with php
I'm trying to retrieve some data from a MySQL database but when I execute the php page it shows a white page. Any idea if and what I do wrong...
$query = mysql_query("SELECT * FROM EMPLOYEES"); while ($row = mysql_fetch_array($query)); { $Ssn=$row['Ssn']; $UnionMembershipNumber=$row["UnionMembershipNumber"]; $fname=$row['Fname']; $surname=$row['Surname']; $StreetName=$row['StreetName']; $StreetNumber=$row['StreetNumber']; $PostalCode=$row['PostalCode']; $Salary=$row['Salary']; echo $fname."".$surname."".$StreetName."".$StreetNumber."".$PostalCode."".$Salary."<br>"; } 开发者_Go百科?>
Yes. Remove the ;
at the end of the while
$query = mysql_query("SELECT * FROM EMPLOYEES");
while ($row = mysql_fetch_array($query))
{
...
you made the mysql_connect(); and mysql_select_db(); correct?
while ($row = mysql_fetch_array($query));
{
Remove the ;
.
Also, try adding error_reporting(E_ALL);
at the beginning of the code for debugging.
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) { // no semicolon
would not hurt, try print_r ($query); before while loop to make sure that you got results, and make sure that your mysql_connect() and mysql_select_db() did not fail.
精彩评论