bobocheez Posted November 6, 2009 Share Posted November 6, 2009 So I have a random number script, but I'm not sure how to store the array values in once cell. Then query the db again and set individual variables for each number. I would just make 5 cells for each number, but more numbers will be added so I don't want the table to get too big. $max = 5; $min = 1; $amount = 5; $x = 0; $numbers[0] = 0; if (($max - $min) > $amount) die('$amount is larger number than $max - $min'); while (count($numbers) < $amount) { $ranvar = rand($min, $max); while(in_array($ranvar, $numbers)) { $ranvar = rand($min, $max); } $numbers[$x] = $ranvar; $x++; } echo "$numbers[0]<br/>"; echo "$numbers[1]<br/>"; echo "$numbers[2]<br/>"; echo "$numbers[3]<br/>"; echo "$numbers[4]<br/>"; $query_rand = "UPDATE hits WHERE id=2 SET order='something', "; mysql_query($query_rand); Link to comment https://forums.phpfreaks.com/topic/180584-solved-how-do-you-store-array-in-db/ Share on other sites More sharing options...
lemmin Posted November 6, 2009 Share Posted November 6, 2009 You should probably make a new table and relate the numbers to your other table. Otherwise, you can implode() the array before you put it in your database and explode it after you grab it back. http://us.php.net/manual/en/function.implode.php http://us.php.net/manual/en/function.explode.php Link to comment https://forums.phpfreaks.com/topic/180584-solved-how-do-you-store-array-in-db/#findComment-952718 Share on other sites More sharing options...
Goldeneye Posted November 6, 2009 Share Posted November 6, 2009 Method 1: Use serialize on the array you want to store in the database and then use unserialize when pulling that same value from the database -- or, as lemmin suggests -- Method 2: implode the array before inserting it into the database. And then explode that string when pulling it from the database. Link to comment https://forums.phpfreaks.com/topic/180584-solved-how-do-you-store-array-in-db/#findComment-952720 Share on other sites More sharing options...
bobocheez Posted November 6, 2009 Author Share Posted November 6, 2009 I'll go with a new table, for now, since I don't know much about the other methods. Thanks Link to comment https://forums.phpfreaks.com/topic/180584-solved-how-do-you-store-array-in-db/#findComment-952730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.