Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Posts
    18

    Unanswered: for loop sql query headaches

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

    PHP Code:
    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:

    PHP Code:
    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

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168

    Re: for loop sql query headaches

    Hi
    The problem with you code is that you are using inval on an array which is not permitted on array and objects.

    For you purpose use this kind of code
    "select * from table where tab_id='$var[$counter]'";
    This will work instead of using inval.

    Regards

    Rajesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •