Hi! That's me again. And I'm still an idiot, and I need yours help.
Terms of tasks:
Show photos with the ratings.
Problem:
Rating display pictures. And if the first base photo have rating 4, the code for all the other photos, too, shows a picture rating 4.
What am I doing wrong?

<?php 

		$sql="SELECT * FROM photo WHERE type='current'";
		$result = mysql_query($sql);
		$rating =$row['votes'];
		
if ($rating >= 0 && $rating <= 1) { $rate = "0"; }
if ($rating >1 && $rating <= 2) { $rate = "../i/shtuki/rt1.gif"; }
if ($rating >2 && $rating <= 3 { $rate  = "../i/shtuki/rt2.gif"; }
if ($rating >3 && $rating <= 4) { $rate  = "../i/shtuki/rt3.gif"; }
if ($rating >4 && $rating <= 5) { $rate  = "../i/shtuki/rt4.gif"; }
if ($rating >5 && $rating <= 6) { $rate  = "../i/shtuki/rt5.gif"; }

		while($row=mysql_fetch_assoc($result)){
		echo '<li>';
		echo '<img src="' .$row['path'] . '" class="phb"/>' .'<p>' . $row['user'] . '</p>';
		echo "<img src=\"$rate\">" ;
		
		echo '</li>';
		
		}

	?>

Recommended Answers

All 2 Replies

You are selecting a picture rating for each photo right??
Then why all of your comparison you didn't put in the loop?

<?php 
 
$sql="SELECT * FROM photo WHERE type='current'";
$result = mysql_query($sql);

while($row=mysql_fetch_assoc($result))
{
	$rating =$row['votes'];

	if ($rating >= 0 && $rating <= 1) { $rate = "0"; }
	if ($rating >1 && $rating <= 2) { $rate = "../i/shtuki/rt1.gif"; }
	if ($rating >2 && $rating <= 3 { $rate  = "../i/shtuki/rt2.gif"; }
	if ($rating >3 && $rating <= 4) { $rate  = "../i/shtuki/rt3.gif"; }
	if ($rating >4 && $rating <= 5) { $rate  = "../i/shtuki/rt4.gif"; }
	if ($rating >5 && $rating <= 6) { $rate  = "../i/shtuki/rt5.gif"; }

	echo '<li>';
	echo '<img src="' .$row['path'] . '" class="phb"/>' .'<p>' . $row['user'] . '</p>';
	echo "<img src=\"$rate\">" ;
 
	echo '</li>';
}
?>

Next you could use more simpler if's, for example:

if ($rating == 2) { $rate = "../i/shtuki/rt1.gif"; }
		elseif ($rating == 3)  { $rate  = "../i/shtuki/rt2.gif"; }
		elseif ($rating == 4) { $rate  = "../i/shtuki/rt3.gif"; }
		elseif ($rating == 5)  { $rate  = "../i/shtuki/rt4.gif"; }
		elseif ($rating == 6)  { $rate  = "../i/shtuki/rt5.gif"; }
		else $rate = "0";

THANK YOU amd_k8!
i see :)
Yes, I'm an idiot. I am ashamed of this really quite silly mistake, I hope that this post can help someone not make such mistakes. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.