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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.