Blade Maker Posted October 28, 2010 Share Posted October 28, 2010 Is there anyway you can do this: rand(1,3,6) for the random function? Please explain in details thanks. Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 28, 2010 Share Posted October 28, 2010 use an array http://php.net/manual/en/function.array-rand.php Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted October 28, 2010 Author Share Posted October 28, 2010 Thanks I hope it works. Quote Link to comment Share on other sites More sharing options...
Dominion Posted October 28, 2010 Share Posted October 28, 2010 quick example (in answer to the pm) <?php $array = array(1,3,6); $rand_keys = array_rand(array_flip($array), 1); echo $rand_keys; ?> i am sure there is a better way but that would work :) Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted October 28, 2010 Author Share Posted October 28, 2010 Its kinda good, but I need to put a variable in that. The variable calls numbers from the database, and I want the numbers to be put into the array and then randomly selected. Am I on the right track? Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted October 29, 2010 Share Posted October 29, 2010 Sources forom Kirby: <?php include "globals.php"; $array = array($_POST['hidden']); $rand_keys = array_rand(array_flip($array), 1); echo $rand_keys; $get1 = mysql_query("SELECT * FROM `inventory` WHERE inv_userid=1 ORDER BY inv_itemid DESC LIMIT 9999"); ?> <form method='POST' > <?php while ($row = mysql_fetch_assoc($get1)) { ?> <input type='hidden' name='hidden' value='<?php echo $row['inv_itemid'];?>' /><?php } ?></form> basically what he want is being able to pick 1 item out of the inventory. This is how I would do it: include "globals.php"; // Retreive how many items the user have and then get a row number randomly $r=mysql_query("select floor(count(*)*rand()) from inventory where inv_userid=1"); $row=mysql_fetch_row($r); $nb=$row[0]; $r=mysql_query("select * from inventory where inv_userid=1 limit $nb,1"); $row=mysql_fetch_assoc($r); // ... you must then continue Quote Link to comment Share on other sites More sharing options...
Blade Maker Posted October 29, 2010 Author Share Posted October 29, 2010 Thanks but I figured out another way but this was good to thanks! 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.