marcus Posted January 1, 2007 Share Posted January 1, 2007 I'm making a restock system and the rows are not being inputted correctly.[code]<?phprequire('../connect.php');$min = date("i");$sql[time] = "SELECT `time` FROM `shops` WHERE `id` =1";$res[time] = mysql_query($sql[time]);$rowtime = mysql_fetch_assoc($res[time]);if($min == $rowtime[time]){//will have array of items//insert into time using BLAH//also update time, if $min > 10 new time will eqaul rand(11,20), if $min > 20, rand(21,30), etc....}else {//die();} $sql = "SELECT * FROM `list_items` WHERE `type` ='Food'"; $res = mysql_query($sql) or die(mysql_error()); $array = array(); $arra2 = array(); $arra3 = array(); $arra4 = array(); $total = mysql_num_rows($res); while ($row = mysql_fetch_assoc($res)) { $array[] = $row['ID']; $arra2[] = $row['item_name']; $arra3[] = $row['url']; $arra4[] = $row['estimate_price']; }foreach($array as $val) { $array = "$val,"; echo "$array";}echo "<br>";foreach($arra2 as $val2){ $arra2 = "$val2,"; echo "$arra2";}echo "<br>";foreach($arra3 as $val3){ $arra3 = "$val3,"; echo "$arra3";}echo "<br>";foreach($arra4 as $val4){ $arra4 = "$val4,"; echo "$arra4";} $num = rand(1,$total); for ($i = 0;$i <= $num; $i++){ if (mysql_query("INSERT INTO `shopstock` (`itemid`,`item_name`,`url`,`price`) VALUES ('$array[$i]','$arra2[$i]','$arra3[$i]','$arra4[$i]');")) { echo $array[$i]." inserted"; } }?>[/code]Basically I get:Full Texts id itemid item_name url price stock place Edit Delete 1 2 Y h 3 0 Edit Delete 2 2 u t 0 0 Edit Delete 3 5 c t 1 0 Edit Delete 4 0 k p 0 0 Edit Delete 5 0 y : 0 0 Edit Delete 6 0 / 0 0 Edit Delete 7 0 R / 0 0 Edit Delete 8 0 i w 0 0 Edit Delete 9 0 c w 0 0 Edit Delete 10 0 e w 0 0 Edit Delete 11 0 , . 0 0 Edit Delete 12 0 t 0 0 Edit Delete 13 0 e 0 0 dont worry about place. Quote Link to comment Share on other sites More sharing options...
Liquix Posted January 1, 2007 Share Posted January 1, 2007 Maybe because you're editing the vars you are using in the foreach loops while they are being parsed, dunno. Try making some new vars for the loops.foreach($array as $val) { $array_a = $val . ","; echo $array_a;} Quote Link to comment Share on other sites More sharing options...
dcro2 Posted January 1, 2007 Share Posted January 1, 2007 Because you're making those arrays a string, each index of it is a character in the string. $array[0] = "Y" $array[1] = "u", etc...You can do that with any string. 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.