I have 1 table on the database 🙁 SQL )
-- id
-- city_name
-- image
and I want to view every images inside them city, for example : USA has 3 images and Canada has 2, it will be looks like :
USA
image 01
image 02
image 03
CANADA
image 01
image 02
I tried this code, it will be view all the records mixed
$results1 = mysql_query("SELECT * FROM gallery");
while($r = mysql_fetch_array($results1)) {
echo $r[city_name]."<hr>";
$city = $r[city_name];
$results2 = mysql_query("SELECT * FROM gallery WHERE city_name='$city'");
while($r = mysql_fetch_array($results2)){
echo '<img border="0" src="'.$r['image'].'">';
}
}
Thanks,
Correction in your code:
You are overwriting `result set $r of first query into second while loop
Second solution: