for loop sql query headache

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jst
Forum Newbie
Posts: 2
Joined: Mon Feb 23, 2004 9:16 pm
Contact:

for loop sql query headache

Post by jst »

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


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();
            }    
        }
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
Post Reply