954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP results in Blank Screen

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

<code>&lt;?
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( &quot;Unable to select database&quot;);
$query=&quot;SELECT * FROM events&quot;;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo &quot;&lt;b&gt;&lt;center&gt;Database Output&lt;/center&gt;&lt;/b&gt;&quot;;
$i=0;
while ($i &lt; $num) {
$title=mysql_result($result,$i,&quot;title&quot;);
$title =mysql_result($result,$i,&quot;title&quot;;
$description =mysql_result($result,$i,&quot;description&quot;;
$organization =mysql_result($result,$i,&quot;organization&quot;;
$start_month =mysql_result($result,$i,&quot;start_month&quot;;
$start_day =mysql_result($result,$i,&quot;start_day&quot;;
$start_year =mysql_result($result,$i,&quot;start_year&quot;;
$start_hour =mysql_result($result,$i,&quot;start_hour&quot;;
$start_min =mysql_result($result,$i,&quot;start_min&quot;;
$start_ampm =mysql_result($result,$i,&quot;start_ampm&quot;;
$end_month =mysql_result($result,$i,&quot;end_month&quot;;
$end_day =mysql_result($result,$i,&quot;end_day&quot;;
$end_year =mysql_result($result,$i,&quot;end_year&quot;;
$end_hour =mysql_result($result,$i,&quot;end_hour&quot;;
$end_min =mysql_result($result,$i,&quot;end_min&quot;;
$end_ampm =mysql_result($result,$i,&quot;end_ampm&quot;;
$time_varies =mysql_result($result,$i,&quot;time_varies&quot;;
$location =mysql_result($result,$i,&quot;location&quot;;
$street1 =mysql_result($result,$i,&quot;street1&quot;;
$street2 =mysql_result($result,$i,&quot;street2&quot;;
$city =mysql_result($result,$i,&quot;city&quot;;
$zip =mysql_result($result,$i,&quot;zip&quot;;
$area =mysql_result($result,$i,&quot;area&quot;;
$href =mysql_result($result,$i,&quot;href&quot;;
$submitter_name =mysql_result($result,$i,&quot;submitter_name&quot;;
$submitter_phone =mysql_result($result,$i,&quot;submitter_phone&quot;;
$submitter_email =mysql_result($result,$i,&quot;submitter_email&quot;;
$primary =mysql_result($result,$i,&quot;primary&quot;;
echo &quot;&lt;b&gt;$title&lt;/b&gt;&quot;;&quot;$description&quot;;&quot;$organization&quot;;&quot;$start_month&quot;;&quot;$start_day&quot;;&quot;$start_year&quot;;&quot;$start_hour&quot;;&quot;$start_min&quot;;&quot;$start_ampm&quot;;&quot;$end_month&quot;;&quot;$end_day&quot;;&quot;$end_year&quot;;&quot;$end_hour&quot;;&quot;$end_ampm&quot;;&quot;$time_varies&quot;;&quot;$location&quot;;&quot;$street1&quot;;&quot;$street2&quot;;&quot;$city&quot;;&quot;$zip&quot;;&quot;$area&quot;;&quot;$href&quot;;&quot;$submitter_name&quot;;&quot;$submitter_phone&quot;;&quot;$submitter_email&quot;;&quot;$primary&quot;;
 
$i++;
}
?&gt;</code>
Clanham
Newbie Poster
2 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

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

<code>&lt;?
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( &quot;Unable to select database&quot;);
$query=&quot;SELECT * FROM events&quot;;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i &lt; $num) {
//code
}
?&gt;</code>

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:
[php]
echo "\nFieldValue\n";
foreach(mysql_fetch_assoc($result) as $key => $value)
{
echo "$key$value\n"
}
echo "";
[/php]

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

Anonymusius
Posting Whiz in Training
238 posts since Aug 2006
Reputation Points: 129
Solved Threads: 11
 

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
tags between each variable. Like this...

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


Hopefully this will help :)

GliderPilot
Junior Poster in Training
86 posts since Sep 2006
Reputation Points: 8
Solved Threads: 4
 

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)

jbennet
Moderator
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
 

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

dr4g
Junior Poster
136 posts since Apr 2007
Reputation Points: 35
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You