Unstoppable Domains โ€” Expired Auctions

Rate My. . .

SpaceshipSpaceship
Watch
Impact
12
Hi,

I was wondering how i can make myself a script that put all the image in a database, then on the homepage it displays a random one, and people can rate it and it shows its rating.

What would it consist of and what would be some coding?

Cheers,
Steven
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Easiest way to do it would be assigning to every picture an unique ID. Perhaps a growing number. Then all you have to do th get a random picture is get a random number from 1 to $number_of_pictures_you_have and pull 1 row from database with that specific images data (url, desc, previous ratings, size, etc)
 
0
•••
Perhaps this will help:

Code:
<?php

require_once ('connect.php');

$query  = "SELECT ImageID FROM Images";
$result = @mysql_query ($query);
$num = mysql_num_rows ($result);

$id = rand(1,$num);

// So basically you see how many records there are in the database, then generate a random number between 1 and that many records

$query2  = "SELECT ImageID, Whatever, SomethingElse FROM Images WHERE ImageID='".$id."' ";
$result2 = @mysql_query ($query2);

?>

Hope that was useful to you. ;)
 
0
•••
it is best not to upload images to the database, although databases can handle this type of data is not the best way to do it.

You could upload them into a folder and upload the filename of the image to the database then when selecting the image use the mysql RAND() function to select the image and put the url for the image into the img src tag when outputting.
 
0
•••
how then would the rating system work for each image?
 
0
•••
Add 2 more fields: RatingTotal and RatingCount.

Use a <SELECT> box and make the selections 1-5 star, or whatever. Add this number to the RatingTotal, then add 1 to the RatingCount. The average would then obviously be RatingTotal / RatingCount.
 
0
•••
or have another table that holds what people have rated the image along with the image id. Then to find the rating simply extract the sum of all the fields that are for that image and divide by the total amount of people who rated it.

Doing it this way would enable you to keep track of who has rated the images already (have another field with their username (if they have 1) or some other distinguishing mark such as an ip address (not fool proof but good enough for what you need). This would get around the majority of people who will try and up the rating of the image by continuously giving it a maximum rating.
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back