Page 1 of 1

How to Loop

Posted: Sat Mar 14, 2009 7:39 am
by nishmgopal
Hey Guys

I am trying to loop through my table so all the records where job_ID=1 is displayed, so far I have the code below and it only returns the first value:

Code: Select all

$sql2="SELECT * FROM ID_Table WHERE Job_ID IN (SELECT Job_ID FROM Job_ID WHERE Job_ID=$Job_ID1)";
$result3 = mysql_query($sql2)
       or die ("Couldn't execute query.");
 
while ($row3=mysql_fetch_array($result3)){
 
        $Skill_ID=$row3['Skill_ID'];
        $Weight=$row3['Weight'];
        }
So basically I want all the skill_id's and the weights associtated with a particular job_id.

Can anyone help?

Re: How to Loop

Posted: Sat Mar 14, 2009 7:56 am
by hasti
hi

Code: Select all

 
   $sql2="SELECT * FROM ID_Table WHERE Job_ID IN (SELECT Job_ID FROM Job_ID WHERE Job_ID=$Job_ID1)";
   $result3 = mysql_query($sql2)
          or die ("Couldn't execute query.");
    
   while ($row3=mysql_fetch_array($result3)){
    
           $Skill_ID[]=$row3['Skill_ID'];
           $Weight[]=$row3['Weight'];
          }
 

Re: How to Loop

Posted: Sat Mar 14, 2009 8:26 am
by nishmgopal
I tried that and i got the return:

Array, Array

Re: How to Loop

Posted: Sat Mar 14, 2009 2:48 pm
by Benjamin

Code: Select all

 
foreach ($Skill_ID as $skill) {
    echo $skill;
}