Page 1 of 1

Problems with my table

Posted: Mon Mar 23, 2009 6:43 pm
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

Re: Problems with my table

Posted: Tue Mar 24, 2009 12:55 am
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:

Re: Problems with my table

Posted: Tue Mar 24, 2009 5:45 am
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?

Re: Problems with my table

Posted: Tue Mar 24, 2009 5:50 am
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....

Re: Problems with my table

Posted: Tue Mar 24, 2009 5:53 am
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

Re: Problems with my table

Posted: Tue Mar 24, 2009 6:18 am
by nishmgopal
yes most likely I can try and do that, will this help me in getting the result I want?

Re: Problems with my table

Posted: Tue Mar 24, 2009 7:02 am
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.