PHP results in Blank Screen

Reply

Join Date: Apr 2007
Posts: 2
Reputation: Clanham is an unknown quantity at this point 
Solved Threads: 0
Clanham Clanham is offline Offline
Newbie Poster

PHP results in Blank Screen

 
0
  #1
May 2nd, 2007
I am trying to display all data from my MYSQL database but it results in a blank page:
  1. <span class="ad_notxt"><code class="inlinecode">
  2. <?
  3. mysql_connect($host,$username,$password);
  4. @mysql_select_db($database) or die( "Unable to select database");
  5. $query="SELECT * FROM events";
  6. $result=mysql_query($query);
  7. $num=mysql_numrows($result);
  8. mysql_close();
  9. echo "<b><center>Database Output</center></b><br><br>";
  10. $i=0;
  11. while ($i < $num) {
  12. $title=mysql_result($result,$i,"title");
  13. $title =mysql_result($result,$i,"title";
  14. $description =mysql_result($result,$i,"description";
  15. $organization =mysql_result($result,$i,"organization";
  16. $start_month =mysql_result($result,$i,"start_month";
  17. $start_day =mysql_result($result,$i,"start_day";
  18. $start_year =mysql_result($result,$i,"start_year";
  19. $start_hour =mysql_result($result,$i,"start_hour";
  20. $start_min =mysql_result($result,$i,"start_min";
  21. $start_ampm =mysql_result($result,$i,"start_ampm";
  22. $end_month =mysql_result($result,$i,"end_month";
  23. $end_day =mysql_result($result,$i,"end_day";
  24. $end_year =mysql_result($result,$i,"end_year";
  25. $end_hour =mysql_result($result,$i,"end_hour";
  26. $end_min =mysql_result($result,$i,"end_min";
  27. $end_ampm =mysql_result($result,$i,"end_ampm";
  28. $time_varies =mysql_result($result,$i,"time_varies";
  29. $location =mysql_result($result,$i,"location";
  30. $street1 =mysql_result($result,$i,"street1";
  31. $street2 =mysql_result($result,$i,"street2";
  32. $city =mysql_result($result,$i,"city";
  33. $zip =mysql_result($result,$i,"zip";
  34. $area =mysql_result($result,$i,"area";
  35. $href =mysql_result($result,$i,"href";
  36. $submitter_name =mysql_result($result,$i,"submitter_name";
  37. $submitter_phone =mysql_result($result,$i,"submitter_phone";
  38. $submitter_email =mysql_result($result,$i,"submitter_email";
  39. $primary =mysql_result($result,$i,"primary";
  40. 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";
  41.  
  42. $i++;
  43. }
  44. ?>
  45. </code></span>
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

Re: PHP results in Blank Screen

 
0
  #2
May 3rd, 2007
Originally Posted by Clanham View Post
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();
$i=0;
while ($i < $num) {
//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 "<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>";
[/php]

I didn't test it, but it should work (for one result, if there are more result you should format the table different).
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 57
Reputation: GliderPilot is an unknown quantity at this point 
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: PHP results in Blank Screen

 
0
  #3
May 3rd, 2007
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:

  1. 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...

  1.  
  2. echo "<b>$title</b> <br />
  3. $description <br />
  4. $organization<br />
  5. $start_month <br />
  6. $start_day <br />
  7. etc...
  8. ";

Hopefully this will help
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,253
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 540
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: PHP results in Blank Screen

 
0
  #4
May 3rd, 2007
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)
Last edited by jbennet; May 3rd, 2007 at 2:16 pm.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Re: PHP results in Blank Screen

 
0
  #5
May 6th, 2007
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
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC