944,198 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1535
  • PHP RSS
May 2nd, 2007
0

PHP results in Blank Screen

Expand Post »
I am trying to display all data from my MYSQL database but it results in a blank page:
PHP Syntax (Toggle Plain Text)
  1. <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>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Clanham is offline Offline
2 posts
since Apr 2007
May 3rd, 2007
0

Re: PHP results in Blank Screen

Click to Expand / Collapse  Quote originally posted by Clanham ...
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).
Reputation Points: 129
Solved Threads: 11
Posting Whiz in Training
Anonymusius is offline Offline
223 posts
since Aug 2006
May 3rd, 2007
0

Re: PHP results in Blank Screen

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:

PHP Syntax (Toggle Plain Text)
  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...

PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 8
Solved Threads: 2
Junior Poster in Training
GliderPilot is offline Offline
57 posts
since Sep 2006
May 3rd, 2007
0

Re: PHP results in Blank Screen

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.
Moderator
Featured Poster
Reputation Points: 1800
Solved Threads: 575
Moderator
jbennet is offline Offline
16,534 posts
since Apr 2005
May 6th, 2007
0

Re: PHP results in Blank Screen

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
Reputation Points: 35
Solved Threads: 5
Junior Poster
dr4g is offline Offline
136 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: help with forms
Next Thread in PHP Forum Timeline: Short guide to include RSS on your website





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC