I am trying to display all data from my MYSQL database but it results in a blank page:

<?
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM events";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"title");
$title =mysql_result($result,$i,"title";
$description =mysql_result($result,$i,"description";
$organization =mysql_result($result,$i,"organization";
$start_month =mysql_result($result,$i,"start_month";
$start_day =mysql_result($result,$i,"start_day";
$start_year =mysql_result($result,$i,"start_year";
$start_hour =mysql_result($result,$i,"start_hour";
$start_min =mysql_result($result,$i,"start_min";
$start_ampm =mysql_result($result,$i,"start_ampm";
$end_month =mysql_result($result,$i,"end_month";
$end_day =mysql_result($result,$i,"end_day";
$end_year =mysql_result($result,$i,"end_year";
$end_hour =mysql_result($result,$i,"end_hour";
$end_min =mysql_result($result,$i,"end_min";
$end_ampm =mysql_result($result,$i,"end_ampm";
$time_varies =mysql_result($result,$i,"time_varies";
$location =mysql_result($result,$i,"location";
$street1 =mysql_result($result,$i,"street1";
$street2 =mysql_result($result,$i,"street2";
$city =mysql_result($result,$i,"city";
$zip =mysql_result($result,$i,"zip";
$area =mysql_result($result,$i,"area";
$href =mysql_result($result,$i,"href";
$submitter_name =mysql_result($result,$i,"submitter_name";
$submitter_phone =mysql_result($result,$i,"submitter_phone";
$submitter_email =mysql_result($result,$i,"submitter_email";
$primary =mysql_result($result,$i,"primary";
echo "<b>$title</b>";"$description";"$organization";"$start_month";"$start_day";"$start_year";"$start_hour";"$start_min";"$start_ampm";"$end_month";"$end_day";"$end_year";"$end_hour";"$end_ampm";"$time_varies";"$location";"$street1";"$street2";"$city";"$zip";"$area";"$href";"$submitter_name";"$submitter_phone";"$submitter_email";"$primary";

$i++;
}
?>

Recommended Answers

All 4 Replies

You misspelled mysql_num_rows, I think that because of that it returned false, so 0. And because of that the entire while loop was never executed.

To shouldn't you get every result manually. I think you should do something like:

echo "<table>n<tr><th>Field</th><th>Value</th></tr>n";
foreach(mysql_fetch_assoc($result) as $key => $value)
{
echo "<tr><td>$key</td><td>$value</td></tr>n"
}
echo "</table>";

I didn't test it, but it should work (for one result, if there are more result you should format the table different).

As mentioned above mysql_num_rows is misspelled. Your while block is not being executed. There are some other changes you will need to make too or else you will get errors when you try and execute the script.

all your mysql_result lines are missing the ) and the end before the ; except for the first one.

You echo statement is a big mess as well. get rid of all the ; in there. You can do that in a couple different ways:

echo "<b>$title</b> $description $organization $start_month $start_day $start_year $start_hour $start_min $start_ampm $end_month $end_day $end_year $end_hour $end_ampm $time_varies $location $street1 $street2 $city $zip $area $href $submitter_name $submitter_phone $submitter_email $primary";

This will put them all on one line though. To have each on it's own line just add <br /> tags between each variable. Like this...

echo "<b>$title</b> <br />
$description <br />
$organization<br />
$start_month <br />
$start_day <br />
etc...
";

Hopefully this will help :)

I had the same problem with PHP ande Mysql but it was in fact that i installed the server wrong (forgot to tell PHP5 where mysql was - PHP5 unlike PHP4 does NOT have mysql support by default)

Yep. Blank page = loop never being executed.

Anonymusius' post about the foreach() will probably be the most important thing, you (Clanham). to learn form these responses.

Good luck on your PHP adventure

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.