nishmgopal Posted March 23, 2009 Share Posted March 23, 2009 Hi guy I am having trouble outputting my data into a html table, my code is: $sql= "SELECT * FROM Person_Skill JOIN Person_ID USING (Person_ID) ORDER BY Person_Name"; $result1 = mysql_query($sql) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result1)) { $pname=$row['Person_Name']; $pskill=$row['Skill_Name']; $score=$row['Score']; $sql2= "SELECT * FROM ID_Table JOIN Job_ID USING (Job_ID) ORDER BY Job_Name"; $result2 = mysql_query($sql2) or die ("Couldn't execute query."); while ($row1=mysql_fetch_array($result2)) { $jname=$row1['Job_Name']; $jskill=$row1['Skill_Name']; $weight=$row1['Weight']; } echo" <table width='200' border='1'><hr> <strong>$pname</strong> <br></br> <tr bgcolor='#999999'> <div align='center'> </tr> <tr>Skill_Name <td>$jskill</td> </tr> <tr>Score <td>$weight</td> </tr> <tr>Skill_Name <td>$pskill</td> </tr>"; } But this doesnt work very well... I want a table with the folowing columns: $jskill $weight $pskill $score Thanks Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/ Share on other sites More sharing options...
FaT3oYCG Posted March 24, 2009 Share Posted March 24, 2009 try this $sql= "SELECT * FROM Person_Skill JOIN Person_ID USING (Person_ID) ORDER BY Person_Name"; $result1 = mysql_query($sql) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result1)) { $pname=$row['Person_Name']; $pskill=$row['Skill_Name']; $score=$row['Score']; $sql2= "SELECT * FROM ID_Table JOIN Job_ID USING (Job_ID) ORDER BY Job_Name"; $result2 = mysql_query($sql2) or die ("Couldn't execute query."); while ($row1=mysql_fetch_array($result2)) { $jname=$row1['Job_Name']; $jskill=$row1['Skill_Name']; $weight=$row1['Weight']; } echo(" <table width='200' border='1'> <hr><strong>$pname</strong></hr> <tr> <td>" . $jname . "</td> <td>" . $jskill . "</td> </tr> <tr> <td>Weight</td> <td>" . $weight . "</td> </tr> <td>" . $pname . "<td> <td>" . $pskill . "</td> </tr> </tr> <td>Score<td> <td>" . $score . "</td> </tr> "; } Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792240 Share on other sites More sharing options...
nishmgopal Posted March 24, 2009 Author Share Posted March 24, 2009 I tried that but it doesnt work. Under the column Skill Name I want all the $jskill to be displayed a different rows...and under the Weight column I want all the $weight to be displayed in different rows... Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792450 Share on other sites More sharing options...
dgoosens Posted March 24, 2009 Share Posted March 24, 2009 try by putting the echo statement into the while loop $sql= "SELECT * FROM Person_Skill JOIN Person_ID USING (Person_ID) ORDER BY Person_Name"; $result1 = mysql_query($sql) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result1)) { $pname=$row['Person_Name']; $pskill=$row['Skill_Name']; $score=$row['Score']; $sql2= "SELECT * FROM ID_Table JOIN Job_ID USING (Job_ID) ORDER BY Job_Name"; $result2 = mysql_query($sql2) or die ("Couldn't execute query."); while ($row1=mysql_fetch_array($result2)) { $jname=$row1['Job_Name']; $jskill=$row1['Skill_Name']; $weight=$row1['Weight']; echo(" <table width='200' border='1'> <hr><strong>$pname</strong></hr> <tr> <td>" . $jname . "</td> <td>" . $jskill . "</td> </tr> <tr> <td>Weight</td> <td>" . $weight . "</td> </tr> <td>" . $pname . "<td> <td>" . $pskill . "</td> </tr> </tr> <td>Score<td> <td>" . $score . "</td> </tr> "; } } Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792458 Share on other sites More sharing options...
nishmgopal Posted March 24, 2009 Author Share Posted March 24, 2009 Still not getting the desired result. I think I might need some other loop function or something, I have changed my code to look like this: $sql= "SELECT * FROM Person_Skill JOIN Person_ID USING (Person_ID) ORDER BY Person_Name"; $result1 = mysql_query($sql) or die ("Couldn't execute query."); while ($row=mysql_fetch_array($result1)) { $pname=$row['Person_Name']; $pskill=$row['Skill_Name']; $score=$row['Score']; $sql2= "SELECT * FROM ID_Table JOIN Job_ID USING (Job_ID) WHERE Job_Name='Manager'"; $result2 = mysql_query($sql2) or die ("Couldn't execute query."); while ($row1=mysql_fetch_array($result2)) { $jname=$row1['Job_Name']; $jskill=$row1['Skill_Name']; $weight=$row1['Weight']; echo(" <table width='200' border='1'> <hr><strong>$pname</strong></hr> <tr> <td>" . $jname . "</td> <td>" . $jskill . "</td> </tr> <tr> <td>Weight</td> <td>" . $weight . "</td> </tr> <td>" . $pname . "<td> <td>" . $pskill . "</td> </tr> </tr> <td>Score<td> <td>" . $score . "</td> </tr> </table>"); } } By adding this WHERE clause in the Job_Name, I was hoping to display a table where all the skills required and their weights are displayed...something like this: Manager Skill Required Weight C 4 Java 3 Leadership 5 [/code] Is there anyway I can achive this result? Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792464 Share on other sites More sharing options...
nishmgopal Posted March 24, 2009 Author Share Posted March 24, 2009 also i want to display each person as a different table, so for example if my database has two people, bob and dave, then there will be one table with the Manager Skill Name, the weight and Daves Score, then another table with Manager Skill Name, Weight and Toms Score.... Manager - Dave SKill Required Weight Score C 4 5 JAVA 3 4 Manager - Tom SKill Required Weight Score C 4 2 JAVA 3 2 Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792475 Share on other sites More sharing options...
dgoosens Posted March 24, 2009 Share Posted March 24, 2009 I am affraid I don't really understand your queries... shouldn't you pass a personID or something into your second query ? Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792484 Share on other sites More sharing options...
nishmgopal Posted March 24, 2009 Author Share Posted March 24, 2009 im not sure my self, hence I am askin for help...you think i need to pass person id on? so use JOIN or something? Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792493 Share on other sites More sharing options...
dgoosens Posted March 24, 2009 Share Posted March 24, 2009 maybe you could post a diagram of your database, or an SQL file ? it is rather hard guessing with your database structure... Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792498 Share on other sites More sharing options...
nishmgopal Posted March 24, 2009 Author Share Posted March 24, 2009 I have attached the strucure.. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/150792-problems-with-my-table/#findComment-792499 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.