Displaying results of an array

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

Displaying results of an array

Post by nishmgopal »

Hi guys, I am trying to display my results as a table, my code is below..

Code: Select all

 
 
$query1 = "SELECT * FROM Job_ID WHERE Job_Name ='$_SESSION[Job_Name]'";
            
  $result2 = mysql_query($query1)
       or die ("Couldn't execute query.");
 
while ($row2=mysql_fetch_array($result2)){
 
        $Job_ID1=$row2['Job_ID'];
            }
    
    
        ////
$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_Name[]=$row3['Skill_Name'];
            $Weight[]=$row3['Weight'];
          }
$sep = '';
$sid_list = '';
foreach ($Skill_Name as $sid) {
  $sid_list .= "$sep$sid";
  $sep = ','; 
}
$sid_list .= '';
 
 
      
        
{
$sep1='';
foreach ($Weight as $wei){
$sid_list1 .= "$sep1$wei";
$sep1=',';
 
}
$sid_list1 .= '';
}
 
?>
 
 
I would like to print the contents of $sid_list and $sid_list1 as a table. Is this possible?

Thank you
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Displaying results of an array

Post by Mark Baker »

As always when I see this, I tell people to join their two queries into a single query
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Displaying results of an array

Post by nishmgopal »

iv done that:

Code: Select all

 
$query="SELECT `Skill_Name`, `Weight`
        FROM ID_Table
        JOIN Job_ID ON ID_Table.Job_ID = Job_ID.Job_ID
        WHERE Job_ID.Job_Name ='{$_SESSION[Job_Name]}'";
 
$result = mysql_query($query) or die ("Couldn't execute query.");
 
while ($row=mysql_fetch_array($result))
{
    $skillTbl .= "<tr><td>{$row['Skill_Name']}</td></tr>\n";
    $WeightTbl .= "<tr><td>{$row['Weight']}</td></tr>\n";
}
 
echo "SKILLS:<br>\n";
echo "<table border='1'><tr><td>{$skillTbl}</tr><tr>{$WeightTbl}</tr></table>\n";
 
 
 
 
?>
 
But yet I still cant display the info as a table with two coloums: Skills and Weight...
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Displaying results of an array

Post by Mark Baker »

Code: Select all

 
$query="SELECT `Skill_Name`, `Weight`
        FROM ID_Table
        JOIN Job_ID ON ID_Table.Job_ID = Job_ID.Job_ID
        WHERE Job_ID.Job_Name ='{$_SESSION[Job_Name]}'";
 
$result = mysql_query($query) or die ("Couldn't execute query.");
 
echo "<table border='1'>\n<tr><th>Skill</th><th>Weight</th></tr>\n";
while ($row=mysql_fetch_array($result))
{
    echo "<tr>";
    echo "<td>".$row['Skill_Name']."</td>\n";
    echo "<td>".$row['Weight']."</td>\n";
    echo "</tr>\n";
}
 
echo "</table>\n";
 
 
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Re: Displaying results of an array

Post by nishmgopal »

thank you very much for you help.
Post Reply