How to Loop

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
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

How to Loop

Post 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?
hasti
Forum Newbie
Posts: 6
Joined: Sat Mar 14, 2009 5:37 am
Location: India
Contact:

Re: How to Loop

Post 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'];
          }
 
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: How to Loop

Post by nishmgopal »

I tried that and i got the return:

Array, Array
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to Loop

Post by Benjamin »

Code: Select all

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