brentmoeller Posted March 7, 2011 Share Posted March 7, 2011 the code im running is $result = mysql_query("SELECT count(*) FROM slinks where approval='1'"); $do = mysql_fetch_row($result); $random = mt_rand(0,$do[0] - 1); $result = mysql_query("SELECT * FROM slinks LIMIT $random, 1"); The above is finished off into a iframe <iframe src="<?php while ($row = mysql_fetch_array($result)){ print $row["url"];}?> "frameborder="0" width="100%" height="100%" name="surfing"id="dframe"></iframe> resulting in a random site loaded ever time the php file is ran now all i need to figure out with a little help from the great users at phpfreaks is how i can get the random site to only be ran one time per user. example click = randomsite1.com click = randomsite2.com click = randomsite3.com click = randomsite4.com click = randomsite5.com click = randomsite5.com = <--SKIP done been called so lets move along click = randomsite6.com I guess somehow im going to have to store the urls that are loaded into a variable and compare the variable to the the random site to make sure we dont get a match. then again i guess i would have to some how figure out how to store the data per unique user as well . Any suggestions would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/ Share on other sites More sharing options...
litebearer Posted March 8, 2011 Share Posted March 8, 2011 only be ran one time per user. Do you mean each user can only run it one time forever, or ??? Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/#findComment-1184295 Share on other sites More sharing options...
brentmoeller Posted March 8, 2011 Author Share Posted March 8, 2011 i dont want the user to randomly get the same website over and over. Lets say you got the below sites stored in the database slinks the script above is going to randomly select one of those sites and its going to run inside a iframe everytime its ran. the user is going to be running this script over and over getting a random site evertime like how they do it @ stumbleupon.com . everytime you stumble you get a new site to look at. You dont want to stumble the same sites over and over. phpfreaks.com php.com yahoo.com google.com msn.com So i need to figure out how to keep the user from getting the same site more than one time. sorry the threads title isn't the best description on what i need done:) Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/#findComment-1184330 Share on other sites More sharing options...
litebearer Posted March 8, 2011 Share Posted March 8, 2011 Well, to do that would necessitate some way of keeping track of what sites the each user has 'seen' per visit (session). I suppose you could have a session variable to which you sequentially add 'visited site', then check to see if the random selection is already in the session variable, if so - chose another - if not add it and display it. (A very quick rough idea) Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/#findComment-1184402 Share on other sites More sharing options...
brentmoeller Posted March 8, 2011 Author Share Posted March 8, 2011 would it be possible to give me some generic/bogus code on how this would be possible? Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/#findComment-1184620 Share on other sites More sharing options...
litebearer Posted March 8, 2011 Share Posted March 8, 2011 VERY rough , untested, un-proof-read, psuedo code... <?PHP session_start(); $visited = array(); if(isset($_SESSIONS['visited'])) { $visited = $_SESSIONS['visited']; } $good = FALSE; while(!$good) { /* code for getting random site here */ $site = some_value; /* check to see if the site is already in the array */ if(!in_array($site,$visited)) { /* add the site to the end of the array */ array_push($visited, $site); /* update the session variable */ $_SESSION['visited'] = $visited; /* let the while loop know we are done */ $good = TRUE; } } /* display the site */ ?> Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/#findComment-1184678 Share on other sites More sharing options...
brentmoeller Posted March 8, 2011 Author Share Posted March 8, 2011 very nice. Il play around a Little bit and see what i can come up with and update this thread thanks for your help my friend Link to comment https://forums.phpfreaks.com/topic/229925-1-unique-site-per-user/#findComment-1184680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.