I haven't been able to figure this one out. On my photography page, I want to display an image at random whenever someone goes to the page. It would probably be best if the image didn't change when they refresh the page, but I haven't even looked at sessions yet, so really I just want to know how to select a random record.
http://www.paulkjohnson.com/photography/
I know how to display it so all I need is the next line of code.PHP Code:<?PHP
$db = @mysql_connect(etc);
mysql_select_db('Photography');
if ($ImageID > 0)
{
$query = mysql_query("SELECT Subject,Filename,Year,Caption FROM photographs WHERE ImageID = '$ImageID'");
$BasePath = 'images/';
$Caption = mysql_result($query,0,"Caption");
$Filename = mysql_result($query,0,"Filename");
$FullPath = "$BasePath$Filename";
echo "<p align=\"center\"><img src=$FullPath></p>";
echo "<p align=\"center\">$Caption</p>";
$Copyright = "Copyright © ";
$Year =mysql_result($query,0,"Year");
$Author = " Paul K. Johnson";
echo "<p align=\"center\">$Copyright$Year$Author</p>";
$query = mysql_query("update photographs set Count = Count +1 where ImageID='$ImageID'");
}
else // display a random image
{
$query = mysql_query("SELECT * FROM photographs");
// pick one at random
}
?>




Reply With Quote