Jump to content

[SOLVED] This SQL code is only echoing one result


DaveLinger

Recommended Posts

$query="SELECT * FROM reviews WHERE type='frozen' ORDER BY title ASC";
$result = mysql_query($query) or die ("Problem with the query".$query. mysql_error());

while ($row = mysql_fetch_array($result)) {

$id = $row['id'];
$title = $row['title'];
$rating = $row['rating'];
$price = $row['price'];

echo "
<tr>
	<td>$title</td>
	<td>$price</td>
	<td>$rating</td>
	<td>";

$rid=$id;
$show="int";
include('../rating.php');

echo "</td>
</tr>
";

}

 

For some reason it only echoes one result, then goes on.

Better version and should tell you how many results:

After figuring it out i think your issue was your var renaming it caused the to get rewritten each iteration of the while loop

<?php
$query="SELECT id,title,rating,price FROM reviews WHERE type='frozen' ORDER BY title ASC";
$result = mysql_query($query) or die ("Problem with the query".$query. mysql_error());
if($qcount = mysql_num_rows($result) >0){
echo "Displaying: ".$qcount." Results<br/><table>";
while ($row = mysql_fetch_array($result)) {
echo "
<tr>
	<td>$row['title']</td>
	<td>$row['price']</td>
	<td>$row['rating']</td>
	<td>";

$rid=$id;
$show="int";
include('../rating.php');  //Don't think you want this here, explain what it is 
echo "</td></tr>\n";
}
echo "</table>";
}
else{
echo "No results found";
}
?>

untested!

Ah, your code helped me find the real problem. The include which you supposed shouldn't be there in fact should, it echoes an important number. Problem is, in that included file, it has an sql query and result by the same name, so I simply changed the query and result in the included file to queryr and resultr, and it works. Thanks

if you don't mind can i see your include cause your query structure was orignally pretty poor (not to rag on you) and I like to help you improve this cause this seems like a weak system.  select queries are not meant to be part of loops ideally

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.