djfox Posted November 3, 2007 Share Posted November 3, 2007 The weighted randomizer I currently have works fine. But as it currently stands, I`d have to update the page every time a new item comes along (and for my site, this is not efficient). Any way for me to have a weighted randomizer that automatically pulls the items from a table even when new items are added to the table? Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 3, 2007 Share Posted November 3, 2007 Yes. But you need to be far more specific about the actual problem. Some context and some code would be a good start. Quote Link to comment Share on other sites More sharing options...
djfox Posted November 3, 2007 Author Share Posted November 3, 2007 Well if you really want my current code...: <?php $option = "link"; $sites[0] = array("javascript:location.reload()", "</a>You found nothing.<p><a href='javascript:location.reload()'>Keep Searching</a>", 1000); $sites[1] = array("explore3.php?id=22&p=5", "</a>You Found a Glow Stick Tube! Click the image to add it to your inventory.<br><a href='explore3.php?id=22&p=5'><img src='collection/glowsticktube.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 30); $sites[2] = array("explore3.php?id=23&p=1", "</a>You Found a String! Click the image to add it to your inventory.<br><a href='explore3.php?id=23&p=1'><img src='collection/string.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 100); $sites[3] = array("explore3.php?id=24&p=4", "</a>You Found a Red Glow Stick Liquid! Click the image to add it to your inventory.<br><a href='explore3.php?id=24&p=4'><img src='collection/glowstickliquidred.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 40); $sites[4] = array("explore3.php?id=25&p=3", "</a>You Found a Purple Glow Stick Liquid! Click the image to add it to your inventory.<br><a href='explore3.php?id=25&p=3'><img src='collection/glowstickliquidpurple.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 50); $sites[5] = array("explore3.php?id=26&p=2", "</a>You Found a Blue Glow Stick Liquid! Click the image to add it to your inventory.<br><a href='explore3.php?id=26&p=2'><img src='collection/glowstickliquidblue.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 60); $sites[6] = array("explore3.php?id=27&p=5", "</a>You Found a Green Glow Stick Liquid! Click the image to add it to your inventory.<br><a href='explore3.php?id=27&p=5'><img src='collection/glowstickliquidgreen.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 30); $sites[7] = array("explore3.php?id=28&p=3", "</a>You Found a Pink Glow Stick Liquid! Click the image to add it to your inventory.<br><a href='explore3.php?id=28&p=3'><img src='collection/glowstickliquidpink.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 50); $sites[8] = array("explore3.php?id=29&p=6", "</a>You Found a Gold Glow Stick Liquid! Click the image to add it to your inventory.<br><a href='explore3.php?id=29&p=6'><img src='collection/glowstickliquidpink.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 5); $sites[9] = array("explore3.php?id=30&p=5", "</a>You Found a Glass Shard! Click the image to add it to your inventory.<br><a href='explore3.php?id=30&p=5'><img src='collection/glassshard.png' border=0></a><p><a href='javascript:location.reload()'>Keep Searching Without Grabbing the Item.</a>", 30); $countsites = count($sites); for($i=0; $i<$countsites; $i++) { for($x=0; $x<$sites[$i][2]; $x++) { if($option != null) { $mylist[] = array($sites[$i][0],$sites[$i][1],$sites[$i][3]); } else { echo("Error deciding option."); exit(); } } } $countlist = count($mylist); $countlist = $countlist - 1; $picker = rand(0, $countlist); if($option == "link") { echo("<a href='" . $mylist[$picker][0] . "'>" . $mylist[$picker][1] . "</a>"); } else if($option == "banner") { echo("<a href='" . $mylist[$picker][0] . "'><img alt='" . $mylist[$picker][1] . "' src='" . $mylist[$picker][2] . "' /></a>"); } else { echo("Error deciding option."); exit(); } ?> And the problem: It reads from what I hand enter. What I want: I want it to read from the mysql database. Quote Link to comment Share on other sites More sharing options...
djfox Posted November 3, 2007 Author Share Posted November 3, 2007 PS. Please don`t criticize how the code has a "bunch of useless junk that`s just taking up space". I know this. It`s one of the things that is being fixed about it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.