Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
06-11-2010, 06:01 AM #1
- Join Date
- Jun 2010
- Thanked 0 Times in 0 Posts
Need help creating a small script
I've been banging my head over this for days.
I'm practicing php by working on a traffic exchange project.
I am working on the Surf Page, where users view two frames. The top shows how many credits they have earned from surfing websites, as well as a countdown timer. Once the timer hits 0, the user can click Next to view another website.
The bottom frame shows this website. I am trying to figure out how to randomly choose a website to show once the user hits Next.
I'm thinking I should have it randomly assign a value (1 to 10000) to each website inside my sql table. Once the random values are set, they are viewed by the user in order. This way the user won't be seeing the same websites over again.
Here is what my table looks like:
Field Type Null Default id int(11) No userid int(11) No url varchar(2083) No credits int(11) No 0 stats int(11) No 0 active tinytext No status text No title varchar(50) No <----------- Once you view the websites, here they are --------------> id userid url credits active title 31 1 http://phpacademy.com 1823 yes php 32 1 http://worldofwarcraft.com 1234567890 yes World 29 2 http://google.com 82749 yes Dixie
Explanation of each cell:
id = Auto incremented value to keep track of websites
userid = id of the user that submitted the website
url = website address
credits = maximum views the website should get in a single day
active = If yes, it is able to be viewed by users
title = no real meaning, just for user's own sites so they know what they are
The website must be active and must have more than 0 credits left in order to be in the new list of sites to be shown.
Any help would be awesome! Would hate to waste 3 more days on this.
07-10-2010, 11:23 PM #2SpikePadleyGuest
Have you tried anything along the lines of this:
$query = mysql_query("SELECT * FROM table_name ORDER BY RAND() LIMIT 1");