marcus Posted December 31, 2006 Share Posted December 31, 2006 [code]$sql = "SELECT * FROM `list_items` WHERE `type` ='Food'";$res = mysql_query($sql) or die(mysql_error());$array = array();while ($row = mysql_fetch_assoc($res)) { $array[] = $row['ID'];}foreach($array as $val) { $array = "$val,"; echo $array;}[/code]Is what I'm trying to do is to have an array ($array) probably explode it, and then do a random number 1,20 and then take the random number and select that many items from the array, and insert them into the database. Quote Link to comment Share on other sites More sharing options...
trq Posted December 31, 2006 Share Posted December 31, 2006 Something like?[code]<?php $sql = "SELECT * FROM `list_items` WHERE `type` ='Food'"; $res = mysql_query($sql) or die(mysql_error()); $array = array(); $total = mysql_num_rows($res); while ($row = mysql_fetch_assoc($res)) { $array[] = $row['ID']; } $num = rand(1,$total); for ($i = 0;$i <= $num; $i++) if (mysql_query("INSERT INTO tbl (fld) VALUES ('{$array[$i]}');")) { echo $array[$i]." inserted"; } }?>[/code] 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.