Jump to content
MakeWebGames

Recommended Posts

Posted

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 :)

Posted

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?

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...