Mike521266 Posted October 16, 2009 Share Posted October 16, 2009 Hi, I am wondering if someone might be able to help me with my problem. I have been looking around forever, trying to figure out how to do this, so anyone who could help, I would be extremely grateful. Thanks in advance, Mike Here is my problem: I have three html pages, and I want all three to be put in a random order on my homepage. They are all advertising with me, so I would like to put them randomly, so they all get their share at the top, second and last. Here are my three html pages http://tilecalgary.com/TileCalgary-HD.html http://tilecalgary.com/TileCalgary-IS.html http://tilecalgary.com/TileCalgary-DJP.html I would like them to come out randomly in this type of a way: http://tilecalgary.com/testpage.html I have made progress, but my code still isn't working... here is what I have: <? $urls = Array("HD","IS","DJP"); $urlCount = UBound($urls) + 1; Randomize; for ($u=0; $u<=$urlCount-1; $u++) { $r = floor( $urlCount * RND() ); $temp = $urls[$u]; $urls[$u] = $urls[$r]; $urls[$r] = $temp; } Set $FSO = Server.CreateObject("Scripting.FileSystemObject"); for ($u=0; $u<=$urlCount-1; $u++) { Set $infile = $FSO.OpenTextFile( Server.MapPath("TileCalgary-".$urls[$u].".html") ); echo $infile.$readAll[ ]; $infile.Close; ?> Am I close, or is this not even close? I really don't know the language, so I have been picking this up in pieces from here and there, and maybe it's just some stupid mistake, and that is why it isn't working. Basically, I would love it if someone much smarter than me could take a look at it, and let me know if it will work or not for what I want. Thanks so much for your time, and I hope someone can help me. Mike Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/ Share on other sites More sharing options...
Lyleyboy Posted October 16, 2009 Share Posted October 16, 2009 The very quick way would be to pop them into into a mysql table. Each record in the table could then have an id (i.e. 1, 2 or 3) Then using rand find a random number between 1 and 3 and then run a query to find the record where the id = your random number. Just one thing to point out is that the random number thing is not actually random so it's entirely possible that No 3 will be output far more times than 1 or 2 thus this client being very upset. If you want to do it properly you need to add a flag field to the table and tick it at each use then use the one after next time. Hope that helps Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/#findComment-937894 Share on other sites More sharing options...
trq Posted October 16, 2009 Share Posted October 16, 2009 Am I close, or is this not even close? Not even. Your code is a random mixture of asp and php (mostly asp), two completely different languages. Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/#findComment-937899 Share on other sites More sharing options...
Mike521266 Posted October 16, 2009 Author Share Posted October 16, 2009 Okay, well, I have another option that I have been working on, do you think this is somewhere close? Does it just need another couple of tweaks to get it to work? Or is this a bust as well? My problem with this one is that it doesn't actually shuffle, it just keeps printing them all out on top of each other, and they always print in the same order, so I continue to see the same one banner every time I refresh the page. <?php $ad_array = array(include("TileCalgary-DJP.php"), include("TileCalgary-HD.php"), include("TileCalgary-IS.php")); shuffle($ad_array); print_r($ad_array); ?> Here is the page that it loads to: http://tilecalgary.com/testpage2.php Thanks very much for taking the time to help me. I really appreciate it. Mike Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/#findComment-938308 Share on other sites More sharing options...
Kaboom Posted October 16, 2009 Share Posted October 16, 2009 You can also add the links you want into a txt file then do this Where ever you want them to show the link 1 at a time randomly put: <?php include('randomizer.php') ?> Then make randomizer.php and inside put <? $textfile ="./links.txt"; $items = file("$textfile"); $item = rand(0, sizeof($items)-1); echo $items[$item]; ?> Then make links.txt and add your 3 links on different lines and it will load then randomly Hope that helps Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/#findComment-938316 Share on other sites More sharing options...
Mike521266 Posted October 16, 2009 Author Share Posted October 16, 2009 So, by suggesting something else, are you saying I'm pretty far off with my code that I have now? I am just hoping that I can make something work like what I have because it is more convenient for me, and I will be dealing with this type of stuff a lot, so it will save me quite a bit of time in the long run if I don't have to open another program and upload it to my server every time... anyway, I don't need to explain why that would save me time, but it just would, so I would like to do it the way I have it if I can... do you think it will work that way if I make a couple changes, or should I just do the text file thing like you said? Thanks, Mike Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/#findComment-938339 Share on other sites More sharing options...
mrMarcus Posted October 16, 2009 Share Posted October 16, 2009 if you have access to a database, then do this: create a table, and name it what you want (change $table to the new name if you do), and then create a field called links. then add each link as a record in that table. //database connection stuff here... $limit = 3; //number of links to display; $table = 'your_table'; $sql = mysql_query ('SELECT `links` FROM '.$table.' ORDER BY RAND() LIMIT '.$limit); while ($res = mysql_fetch_assoc ($sql)) { echo $res['links']; } Link to comment https://forums.phpfreaks.com/topic/177879-shuffling-html-pages-on-a-master-page/#findComment-938347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.