Image Rating System
Posted: Thu Mar 26, 2009 9:14 pm
Hi, I'm trying to make a system where users are served up random images from the database. But I am trying to make it so that the user wont be shown a previous image they already voted/looked at.
Currently I'm not getting pictures shown since i added the thing that stops previous images being shown more than once:
Thanks for your help 
Currently I'm not getting pictures shown since i added the thing that stops previous images being shown more than once:
Code: Select all
<?PHP
session_start() ;
if (!file_exists("php/dbconnect.php"))
{
die("Database settings not found, administrator intervention required.") ;
}
else
{
require("php/dbconnect.php") ; //Must connect to the database.
}
$_SESSION['idview'] ;
$_SESSION['i'] ;
$photoids = explode(" ",$_SESSION['idview']) ; //Bring out the ids, array.
$photo_count = count($photoids) ; //How many pictures the user has viewed.
$countq = ("SELECT image_id FROM image_bank") ; //Count how many cakes are in the base first.
$count = mysql_query($countq) ;
$numrows = mysql_num_rows($count) ;
$image_select = rand(1,$numrows) ; //Assign the max random number based on how many results there are.
echo "$photo_count" ;
echo "$i" ;
if($photo_count == 0)
{
$query = "SELECT * FROM image_bank WHERE image_id = $image_select" ;
$result = mysql_query($query) ;
while($row = mysql_fetch_array($result))
{
$dbtitle = $row['title'] ;
$imgsrc = $row['image_url'] ;
$imageid = $row['image_id'] ;
if(empty($_SESSION['idview']))
{
$_SESSION['idview'] = $row['image_id'] ;
}
else
{
$_SESSION['idview'] .= " " ;
$_SESSION['idview'] .= $row['image_id'] ; //Add the image id to what the user has viewed.
}
}
}
else
{
//Dont show previous images the user has already rated.
if($_SESSION['i'] < $photo_count)
{
$_SESSION['i'] + 1 ;
if($photoids[$_SESSION['i']] == $imageid)
{
$image_select = rand(1,$numrows) ;
$query = "SELECT * FROM image_bank WHERE image_id = $image_select" ;
$result = mysql_query($query) ;
while($row = mysql_fetch_array($result))
{
$imageid = $row['image_id'] ;
}
}
else
{
$query = "SELECT * FROM image_bank WHERE image_id = $image_select" ;
$result = mysql_query($query) ;
while($row = mysql_fetch_array($result))
{
$dbtitle = $row['title'] ;
$imgsrc = $row['image_url'] ;
$imageid = $row['image_id'] ;
if(empty($_SESSION['idview']))
{
$_SESSION['idview'] = $row['image_id'] ;
}
else
{
$_SESSION['idview'] .= " " ;
$_SESSION['idview'] .= $row['image_id'] ; //Add the image id to what the user has viewed.
}
}
}
}
}
echo $_SESSION['idview'] ;
include("php/dbdisconnect.php") ;
?>