Morning freaks,
I have pulled multiple rows out of a mysql db and now I'm in a while loop, trying to add a couple values to each result and insert those into another table. It's not working.
My current code snippet looks like so:
$sql1 = "SELECT date, hour
FROM table1
where date = '$somedate'";
$result1 = mysqli_query($cxn, $sql1) or die ("sql1 transpo in test failed: " . mysqli_error($cxn));
while ($row1 = mysqli_fetch_assoc($result1)){
extract($row1);
$weekday = date("w", strtotime($date));
if ($weekday ==0 ) { //create variables to add to hour/date variables, and insert each corresponding set of values into another table
switch($hour){
case $hour =="01":
$eggs_price = $eggs_cost*0.567*$sunday_hour_01/62;
$bread_price = $bread_cost*0.567*$sunday_hour_01/62;
break;
case $hour =="02":
$eggs_price = $eggs_cost*0.567*$sunday_hour_02/62;
$bread_price = $bread_cost*0.567*$sunday_hour_02/62;
break;
case $hour =="03":
$eggs_price = $eggs_cost*0.567*$sunday_hour_03/62;
$bread_price = $bread_cost*0.567*$sunday_hour_03/62;
break;
case $hour =="04":
$eggs_price = $eggs_cost*0.567*$sunday_hour_04/62;
$bread_price = $bread_cost*0.567*$sunday_hour_04/62;
break;
/////etc., up to hour = 24/////
}
//////// put query results into food table
$sql2 = "INSERT IGNORE into food (date, hour, eggs_price, bread_price)
VALUES ('$date', '$hour', '$eggs_price', '$bread_price')";
$result2 = mysqli_multi_query($cxn, $sql2) or die ("sql2 failed, for this reason: " . mysqli_error($cxn));
echo "<pre>hour: ";
echo $hour." ".$eggs_price;
echo "</pre>";
}
The echoes at the end output the proper number of rows for whatever date/time I put in, which I thought would ensure that the insert would iterate through the same loop in the same way.
But the insert only puts one row (the first hour) into the food table, and that's it.
What am I doing wrong?