Jump to content

While loop not returning data from database


itsjames

Recommended Posts

Hi there,

My snippet of code below is supposed to present data from my MySQL database in a table. However, when the code is executed, I am presented with a totally blank page.

while( $row = mysql_fetch_array( $runQuery )
{
// determine if self collect is available
if ( $row["selfcollect"] = 1 )
	{ $collect = "Yes" ; }
else
	{ $collect = "No" ; }

// create the output
$output = "<table width=\"450\" border=\"0\"><tr>";
$output .= "<td colspan=\"2\" class=\"resultTitle\">" . $row["name"] . "</td>";
$output .= "<td rowspan=\"3\" align=\"center\" width=\"110\" height=\"110\"><a href=\"#\" onclick=\"window.open('images/database/" . $row['image'] . ".jpg','Photo','width=600,height=550,scrollbars=yes')\"><img src=\"images/database/" . $row["image"] . ".jpg\" border=\"0\" /></a></td>";
$output .= "</tr><tr>";
$ouptut .= "<td width=\"170\"><p><strong>Category:</strong> " . $search . "</td>";
$output .= "<td width=\"170\"><strong>Dimensions:</strong> " . $row["dimensions"] . "<br />";
$output .= "<strong>Price:</strong> " .  $row["price"] . "</td>";
$output .= "</tr><tr>";
$output .= "<td colspan=\"2\"><strong>Self collect available:</strong> " . $collect . "</td>";
$output .= "</tr><tr>";
$output .= "<td colspan=\"3\">" . $row["longdesc"] . "</td>";
$output .= "</tr></table>";

// display the output
return $output;
}

 

Any ideas where I could be going wrong?

 

Thanks

Well, that should generate a parse error when the page loads, but are you sure that the SQL is returning any data? Add a test to see and then display a message if no records returned:

<?php
if(mysql_num_rows($runquery)==0){
    print 'OOPS! No data returned<br>';
}
else{
    while(....){}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.