Pulling Up Detailed Lists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

If you want to show all the listings you have to iterate through your result set. So something like this should do the trick.

Code: Select all

     else
     {
          while ($row = mysql_fetch_assoc($display))
          {
               $output. = $row['date'] . $row['task'] . $row['points'] . $row['notes'] . '<br />';
               print($output);
          }
     }
Just paste that in place of the old code.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

bah... i do that and the page goes blank again
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

4Boredom wrote:bah... i do that and the page goes blank again
Because there is a parse somewhere.
SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

And what I put is slightly incorrect. The print should be outside the loop, otherwise you'll see a lot of the same things listed over and over.

Code: Select all

     else
     {
          while ($row = mysql_fetch_assoc($display))
          {
               $output. = $row['date'] . $row['task'] . $row['points'] . $row['notes'] . '<br />';
          }
          print($output);
     }
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

Ok ive broken down the code taking stuff out with comments, and something between line 3 and after is what is killing the code and making the page go blank..

yet i see no errors, and reports arent doing anything... and when i edited my php.ini it messed stuff up

anyone see an error here?

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "'"); 
$output = '';  

if (!$display) 
{ 
print("A database error has occurred. Please contact your administrator"); 
} 
else  
{
$row = mysql_fetch_array($display);
if(!empty($row['tasknum']))
{
echo 'You have no tasks recorded on record.';
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Start indenting your code, you might notice something you didn't before.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

I had it indented and just switched it that way again.. i simply CANT find the error... ive changed the ' to " and vice versa on echos and prints... nothing happening.. white page... and when I comment up until this section it works so it must be here

Code: Select all

if(!$display) 
	{ 
		print('A database error has occurred. Please contact your administrator'); 
	} 
else  
	{
		$row = mysql_fetch_array($display);
		if(!empty($row['tasknum']))
	{
		echo "You have no tasks recorded on record.";
	}}
the whole code is

Code: Select all

$display= mysql_query("SELECT * FROM `points` WHERE `username`= '" . $username . "'"); 
$output = '';  

if(!$display) 
	{ 
		print('A database error has occurred. Please contact your administrator'); 
	} 
else  
	{
		$row = mysql_fetch_array($display);
		if(!empty($row['tasknum']))
	{
		echo "You have no tasks recorded on record.";
	} }


if(!mysql_num_rows($display)) 
     { 
          print('You have no tasks recorded on record.'); 
     } 
else 
     { 
				 while ($row = mysql_fetch_assoc($display)) 
          { 
				  $output. = $row['date'] . $row['task'] . $row['points'] . $row['notes'] . '<br />'; 
          } 
				 print($output); 
     }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Although I would describe the code as poorly formatted, I do not see a parse error right off.

What I do see is a few logic errors and a potentially undefined variable.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

and thats what confuses me.. i dont think it would be blank unless it was parse?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's quite possible to not be a parse error and still not print anything. How? The query returns one row.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

yes but its even killing all of my html above that
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Then that's not the whole code. You may have an error elsewhere.

If possible, test the code on a more local server (like your own machine) where you can control the error settings more easily.
Post Reply