<?php $galleries = array(); $sql = "SELECT * FROM gallery ORDER BY id"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $galleries[] = array("id" => $row["id"], "name" => $row["name"]); // I am assuming that name is a field in the `gallery` table } foreach($galleries as $gallery) { $sql = "SELECT * FROM photos WHERE galleryid = ".$gallery["id"]." ORDER BY RAND() LIMIT 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($sql); print "<p>"; print "<img src='http://ghhotel.com.au/images/photos/".$row["address"]."' />"; // I am assuming that url is a field in the `images` table print "<br />"; print "<a href='http://ghhotel.com.au/gallery/".$gallery["name"]."'>".$gallery["name"]." ".$gallery["id"]."</a>"; // this is the link to your gallery page print "</p>"; } } ?>
however I get the following error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ghhotel/public_html/photos.php on line 151
Hi Russell, Your loop should
Hi Russell,
Your loop should be:
<?foreach($photos as $photo)
{
print $photo["html"] . "";
}
?>
Cheers,
David.
So I changed the code to
So I changed the code to this
<?php$galleries = array();
$sql = "SELECT * FROM gallery ORDER BY id";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
$galleries[] = array("id" => $row["id"], "name" => $row["name"]); // I am assuming that name is a field in the `gallery` table
}
foreach($galleries as $gallery)
{
$sql = "SELECT * FROM photos WHERE galleryid = ".$gallery["id"]." ORDER BY RAND() LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($sql);
print "<p>";
print "<img src='http://ghhotel.com.au/images/photos/".$row["address"]."' />"; // I am assuming that url is a field in the `images` table
print "<br />";
print "<a href='http://ghhotel.com.au/gallery/".$gallery["name"]."'>".$gallery["name"]." ".$gallery["id"]."</a>"; // this is the link to your gallery page
print "</p>";
}
}
?>
however I get the following error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ghhotel/public_html/photos.php on line 151
Hello Russell, My apologies
Hello Russell,
My apologies - what I presume is your line 151:
$row = mysql_fetch_assoc($sql);...should have been:
$row = mysql_fetch_assoc($result);Cheers,
David.