Jump to content

Need help creating a small script


Smudly

Recommended Posts

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.

 

Thanks!

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/204460-need-help-creating-a-small-script/
Share on other sites

As a side note I did something remotely close to this before and the random number thing gets a alot of user complaints reguarding seeing the same page over and over.

 

I recommend you start them at a random table row and from there they go up or down the table incrementally. That way it's guaranteed to be a long time before they see the same site again. Once they get to the top or bottom just send them to the opposite side of the table and let them keep going.

 

 

edit--- I read your post a little more carefully... Just store your web addresses in the data base with a standard incremental key. Then have your user start at a random row as i said above. Everytime they click next you should have an IF statement checking to see if the site is active... if it is then are the credits >3. If not, skip that row.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.