Problems with my table

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

Problems with my table

Post by nishmgopal »

Hi guy I am having trouble outputting my data into a html table, my code is:

Code: Select all

 
 
$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
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Problems with my table

Post by jaoudestudios »

Because that is not valid html! You need something like this...

Code: Select all

 
<table>
  <tr>
       <td>Skill_Name</td>
       <td>$jskill</td>
  </tr>
  <tr>
         <td>Score</td>
         <td>$weight</td>
  </tr>
  <tr>
        <td>Skill_Name</td>
        <td>$pskill</td>
  </tr>
</table>
Note: You would go a long way and save yourself a lot of time if you did some reading up on html, and definitely worth using CSS - constructive comment :wink:
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Problems with my table

Post by nishmgopal »

Tried that but no luck...

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:

Code: Select all

 
 
$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

Code: Select all

 
<table width="200" border="0">
  <tr>
    <td>Skill Required</td>
    <td>Weight</td>
    <td>Score</td>
  </tr>
  <tr>
    <td>C</td>
    <td>4</td>
    <td>1</td>
  </tr>
  <tr>
    <td>Java</td>
    <td>3</td>
    <td>5</td>
  </tr>
  <tr>
    <td>Leadership</td>
    <td>3</td>
    <td>5</td>
  </tr>
</table>
 
Is there anyway I can achive this result?
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Problems with my table

Post by nishmgopal »

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....
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Problems with my table

Post by jaoudestudios »

You are doing 2 queries inside each other, are you able to combine them into 1 query? As this would make it easier to manage
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Problems with my table

Post by nishmgopal »

yes most likely I can try and do that, will this help me in getting the result I want?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Problems with my table

Post by jaoudestudios »

I am not 100% sure what you want and I am not familiar with your schema, but it should definitely make it easier to achieve many things as you wont have nested loops.
Post Reply