List:General Discussion« Previous MessageNext Message »
From:Karthick Subramanian Date:April 8 2010 4:37am
Subject:problem reading array data
View as plain text  
I need to read an array's content using a while loop and inside the loop
read another array's content. Using the variables from the two arrays I need
to execute a query. My problem is the inner while loop reads all records of
the array whereas the outer while loop exits after reading the first record.
That is after execution of the inner while loop finishes, the control does
not move to the outer while loop to read the next array element.

I am appending my code below. Please help me solve this problem

$arrdata  = mysql_query("SELECT OldDeptCode, MajorCode FROM
tblolddeptcodemajorcode");

$result2 = mysql_query("SELECT SSN, DeptCode, ActCode FROM
tblapprovedactivitydetail");

while($info = mysql_fetch_assoc($arrdata))
{
     $OldDeptCode = $info['OldDeptCode'];
     $MajorCode = $info['MajorCode'];

    while($row2 = mysql_fetch_assoc($result2))
    {
        $SSN = $row2['SSN'];
        $DeptCode = $row2['DeptCode'];
        $ActCode = $row2['ActCode'];

        $query = "INSERT INTO test1 (SSN, MajorCode, ActCode) VALUES
('$SSN', '$MajorCode', '$ActCode')";

        if($OldDeptCode != 'COAS' && $OldDeptCode != 'CSS' && $OldDeptCode
!= 'EC' && $OldDeptCode != 'EECS' && $OldDeptCode != 'FW' &&
$OldDeptCode !=
'GEO' && $OldDeptCode != 'SED' && $OldDeptCode != 'VM' &&
$OldDeptCode ==
$DeptCode)
        {
        mysql_query($query);
        }
   }
    echo "done";
}
echo "all done";



Thank you

Thread
problem reading array dataKarthick Subramanian8 Apr
  • Re: problem reading array datanwood8 Apr
    • Re: problem reading array dataJohan De Meersman8 Apr