Page 1 of 1

Comparison between two photos

Posted: Sat Jan 08, 2011 12:15 am
by dondregreen
I want to create a comparison script!
like there are 2 photos , ull get a option to vote for any1
when the person votes for any of the 1 photo.. in the database..the no increments each time a person votes for a photo!

how do i go about!

Re: Comparison between two photos

Posted: Sat Jan 08, 2011 10:46 am
by Neilos
Sounds like FaceMash. Is your name Mark? lol

You'll need to create a table with a column that identifies the image to a record and a column that contains the rating. You'll also want to have columns for any extra details, like name etc...

If it is random you'll want to perform a query to get the number of saved images and pick a random number between 1 and that number;

Code: Select all

<?php

include("database_connect.php");

$query = "SELECT id FROM images;";
$result = mysql_query($query);
$rows = mysql_num_rows($result);

$rand1 = rand(1, $rows);
$rand2 = rand(1, $rows);

while ($rand1 == $rand2) {
$rand2 = rand(1, $rows);
}

// Then perform queries to pull the records for each image id

$query = "SELECT * FROM images WHERE id='$rand1';";
$result = mysql_query($query);
$image1 = mysql_fetch_array($result, MYSQL_ASSOC);

$query = "SELECT * FROM images WHERE id='$rand1';";
$result = mysql_query($query);
$image2 = mysql_fetch_array($result, MYSQL_ASSOC);

// Then display the images and create a form for the image where
// there are check boxes with values equal to the $image#['id']
// ie pick image 1[] image 2[] and the action posts the chosen 
// variable to a script

?>
The other script would pull the record in the same manner using the id that is sent in the POST, read the current rating, add 1 to it and then update the record with the new rating.