Page 1 of 1

Query returning blank page

Posted: Thu May 14, 2009 8:17 pm
by divito
Been having issues all night with a bunch of my code and files and am getting really angry, but this one is one I'm most confused about.

It returns a blank page. Turning on error reporting for PHP and for MySQL shows nothing unless I purposefully make something wrong, but leaving it as is just gives me a blank page. What gives?

Code: Select all

<?
 
include ("db_connection");
 
$query = "SELECT * FROM Events";
$result = MYSQL_QUERY($query) or die('Query Failed');
 
while ($list = mysql_fetch_assoc($result)) {
   
    $start = $list['Start'];
    $end = $list['End'];
    $name = $list['Name'];
    $location = $list['Location'];
    $venue = $list['Venue'];
    $money = $list['Money'];
    $games = $list['Games'];
    
    $date_array = explode("-",$start);
    $date_array2 = explode("-",$end);
        
    $year = $date_array[0];
    $month = $date_array[1];
    $day = $date_array[2];
    $end = $date_array2[2];
    $month2 = $date_array2[1];
    
    if ($month != $month2) {
    
    echo "Event Name: ".$name."<br>";
    Month($month);echo " ".$day."-"; Month($month2); echo " ".$end.", ".$year;
    echo "Location: ".$location."<br>";
    echo "Venue: ".$venue."<br>";
    echo "Total Prize Money: ".$money."<br>";
    echo "Games: ".$games."<br>";
    } else {
    
    echo "Event Name: ".$name."<br>";
    Month($month);echo " ".$day."-".$end.", ".$year;
    echo "Location: ".$location."<br>";
    echo "Venue: ".$venue."<br>";
    echo "Total Prize Money: ".$money."<br>";
    echo "Games: ".$games."<br>";
    
    }
    }
?>

Re: Query returning blank page

Posted: Thu May 14, 2009 8:27 pm
by ldougherty
This line is throwing an error when I try and replicate the code on my server

Code: Select all

Month($month);echo " ".$day."-"; Month($month2); echo " ".$end.", ".$year;
it says

Fatal error: Call to undefined function Month() in /var/www/vhosts/ldollar.com/httpdocs/test.php on line 38

Use this instead

Code: Select all

echo "Month($month)";echo " ".$day."-".$end.", ".$year;
That should work.

Re: Query returning blank page

Posted: Thu May 14, 2009 8:29 pm
by divito
I have my function setup just above my db connection include (it has a return so it doesn't need an echo).

Re: Query returning blank page

Posted: Thu May 14, 2009 9:18 pm
by califdon
divito wrote:I have my function setup just above my db connection include (it has a return so it doesn't need an echo).
Huh? Are you under the mistaken impression that because a function returns a value, it doesn't need to be echoed?????

Re: Query returning blank page

Posted: Thu May 14, 2009 9:20 pm
by divito
Perhaps not in all cases, but when I originally made the function and tried to echo it, it didn't work. When I removed the echo, it did. :|

Re: Query returning blank page

Posted: Thu May 14, 2009 9:42 pm
by ldougherty
a good method to determine if the page is failing to load at all ie PHP error or if your results just aren't coming back as expected..

create a title tag in the head and give it a value. If the page parses then your title will show, if you have a PHP error you will not even see the title.

Re: Query returning blank page

Posted: Thu May 14, 2009 9:53 pm
by divito
Title shows, still blank page. :banghead:

Re: Query returning blank page

Posted: Thu May 14, 2009 10:36 pm
by ldougherty
OK, that means your query is running since your not getting the DIE message but no results.

Try echoing out random text in different places such as before the while loop, in the while loop, and after the while loop to see what works and what doesn't.

Re: Query returning blank page

Posted: Thu May 14, 2009 10:45 pm
by Benjamin
How about turning on error reporting so you don't have to "guess" at what the issue is. Put this at the top of your code and post the results please.

Code: Select all

 
error_reporting(E_ALL);
ini_set("display_errors", 1);
 

Re: Query returning blank page

Posted: Fri May 15, 2009 1:47 am
by jaoudestudios
astions wrote:How about turning on error reporting so you don't have to "guess" at what the issue is. Put this at the top of your code and post the results please.

Code: Select all

 
error_reporting(E_ALL);
ini_set("display_errors", 1);
 
Good idea.

Always develop with full error reporting on!

Re: Query returning blank page

Posted: Fri May 15, 2009 6:16 am
by divito
divito wrote:Been having issues all night with a bunch of my code and files and am getting really angry, but this one is one I'm most confused about.

It returns a blank page. Turning on error reporting for PHP and for MySQL shows nothing unless I purposefully make something wrong, but leaving it as is just gives me a blank page. What gives?

Re: Query returning blank page

Posted: Fri May 15, 2009 6:32 am
by jaoudestudios
this probably wont fix it, but use the full php tags and all functions should be in lower case (i.e. MYSQL_QUERY)

Re: Query returning blank page

Posted: Fri May 15, 2009 6:56 am
by divito
I have full tags in the actual file, I just used the short one when I pasted some the code here. My site has no issue with short tags though. And I changed the function to lower case as requested; was just like that from an old tutorial so I always just copied it over.

As you guessed, didn't fix it though.

Re: Query returning blank page

Posted: Fri May 15, 2009 8:18 am
by Benjamin
There are two possible issues. 1. Your script has a fatal error. 2. The query isn't returning any records.

Re: Query returning blank page

Posted: Fri May 15, 2009 8:34 am
by divito
I managed to fix it. I moved the include for the db connection after the function and it magically started working. Anyone have an explanation for that one?