Jump to content

Rows not inserting corrected


marcus

Recommended Posts

I'm making a restock system and the rows are not being inputted correctly.

[code]
<?php
require('../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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.