Hi Guys,
New to the forum, and still learning PHP. first time i’ve had to deal with MD arrays, and getting a bit stuck.
my query is generating INSERT INTO 4_kpiresults (kpi, kpi_id, date, value) VALUES (, 4, 23/05/2012, )(PD, , 23/05/2012, )(, , 23/05/2012, 3)(, 5, 23/05/2012, )(PN, , 23/05/2012, )(, , 23/05/2012, 4)
but as you can see it is showing incorrectly. It should be showing the following
INSERT INTO 4_kpiresults (kpi, kpi_id, date, value) VALUES (PD, 4, 23/05/2012, 3)(PN, 5, 23/05/2012,4)
I have a suspicion it is to do with the foreach section, but im at a loss as to were to go from here.
My code for the MD array and sql query is:
[php]
$date1 = date(“d/m/Y”);
if (isset($_POST['mode'],$_POST['insertkpi']) && $_POST['mode']=='insert') {
$values = array();
foreach ($_POST[‘insertkpi’] as $value) {
$id1 = mysql_real_escape_string($value['id']);
$name1 = mysql_real_escape_string($value['name']);
$value1 = mysql_real_escape_string($value['value']);
$values[] = "($name1, $id1, $date1, $value1)"; // quoted value, not the raw value
echo $values;
}
$query_values = implode(’’, $values);
$query = “INSERT INTO $value3 (kpi, kpi_id, date, value) VALUES $query_values”;
echo $query;
}
[/php]
Here is part of my code for my table, it is in a while loop as the table is created from data from 2 different mysql tables:
[php]
<td><input type=\"hidden\" name=\"insertkpi[][id]\" maxlength=\"3\" size=\"1\" value=\"".$kpiid. "\"/><input type=\"hidden\" name=\"insertkpi[][name]\" maxlength=\"3\" size=\"1\" value=\"".$resultc['name']. "\"/><strong>".$resultc['name']. "</strong></td>
<td><strong>".$day."</strong></td>
<td><strong>".$mth."</strong></td>
<td><strong>".$yrlytotal."</strong></td>
<td><strong>".$kpires['value']."</strong></td>
<td><strong>".$rowa['value']."</strong></td>
<td><strong>".$rowb['value']."</strong></td>";
if ($kpires[‘value’] < 1) {
echo “
}
else {
echo “
}
echo “
} ?>
[/php]my table works find, however its just the MD array to query i need to fix