nishmgopal Posted March 14, 2009 Share Posted March 14, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/149377-using-loop/ Share on other sites More sharing options...
RichardRotterdam Posted March 14, 2009 Share Posted March 14, 2009 what does your table(s) look like? Quote Link to comment https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784521 Share on other sites More sharing options...
hastishah Posted March 14, 2009 Share Posted March 14, 2009 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']; } Quote Link to comment https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784522 Share on other sites More sharing options...
nishmgopal Posted March 14, 2009 Author Share Posted March 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784526 Share on other sites More sharing options...
premiso Posted March 14, 2009 Share Posted March 14, 2009 $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. Quote Link to comment https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784560 Share on other sites More sharing options...
nishmgopal Posted March 14, 2009 Author Share Posted March 14, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/149377-using-loop/#findComment-784580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.