Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/150792-problems-with-my-table/
Share on other sites

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>
"; 
  }

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>
   ";
}
  }

 

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?

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

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.