for loop sql query headache
Posted: Thu Feb 26, 2004 5:17 am
hi
im trying to write code to update some tables in my db. an array is built from exploding a string taken from a textarea. like so....
i had it all working for one element in a foreach loop but as i needed to update two ive used a for loop. however when i run the script only the first elements of the array are updated with further iterations only returning zeros. here the loop:
ive hardset the $counter just to make sure that there was nothing wrong when evaluating termination.
can someone please point out to me whats going wrong? im confused.
cheers
j
im trying to write code to update some tables in my db. an array is built from exploding a string taken from a textarea. like so....
Code: Select all
if(!empty($formVars["PCRRunSample"]))
{
$sampstring = rtrim($formVars["PCRRunSample"]);
$sampstring = preg_replace("/(\r\n)+/", "\r\n", $sampstring);
$sampstring = explode("\r\n", $sampstring);
}i had it all working for one element in a foreach loop but as i needed to update two ive used a for loop. however when i run the script only the first elements of the array are updated with further iterations only returning zeros. here the loop:
Code: Select all
if(!empty($posstring) && !empty($sampstring))
{
for($counter = 0; $counter < 3; $counter++)
{
$query = "INSERT INTO PCRPosition SET PCRRun_idPCRRun = $idPCRRun, PCRPositionNum = ".intval($posstring[$counter]) .
", Sample_idSample = ".intval($sampstring[$counter]);
if(!(@ mysql_query ($query, $connection)))
showerror();
}
}can someone please point out to me whats going wrong? im confused.
cheers
j