Jump to content

Recommended Posts

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:

 

$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?

 

Link to comment
https://forums.phpfreaks.com/topic/149377-using-loop/
Share on other sites

hi just try this

 

$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'];
          }

Link to comment
https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784522
Share on other sites

I tried that code and the return i got was:

 

Array Array

 

Also my tables looks like this:

 

ID_Table:

 

ID Job_ID Skill_ID Weight

1    1        1          4

2    1        2          3

3    1        3          4

4    2        1          5

 

So what this means is that, the job with Job_ID = 1 has 3 skills (1,2,3) with their weights 4, 3 and 4 respectively.

 

So running my sql should return 1,2,3 with 4,3,4 for job id 1.

Link to comment
https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784526
Share on other sites

$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'];
          }
echo "<pre>";
print_r($Skill_ID);
print_r($Weight);
echo "</pre>";

echo "The first skill returned is {$Skill_ID[0]}<br />";
echo "The first weight returned is " . $Weight[0] . "<br />";

 

array I would read up on arrays and their usage, as it is imperative to know how to use them for sql etc.

 

Link to comment
https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784560
Share on other sites

Thank you for that.

 

But how can I use that $Skill_ID[] in my next sql statement.

 

Basically now I am trying to pull out the name of the skill based on the Skill_ID, the code is:

 

$sql3="SELECT * FROM Skill_ID WHERE Skill_ID='$Skill_ID[]";
$result4 = mysql_query($sql3)
           or die ("Couldn't execute query.");
   
    while ($row4=mysql_fetch_array($result4)){

 

but it is not working. 

 

All I want to do is, get all the skill id's that any particular job_id is associated with, and then get all the skill names based on all the skill_id's.  I thought the best way for this was to have multiple sql statemens with stored varibles?

 

Link to comment
https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784580
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.