Retrieve table rows to table headers in PHP

echo ‘

’;
$items = mysql_query('SELECT g.id

, g.name

, g.courseid FROM items g’);
$rows = array();
while($row = mysql_fetch_array($items))
$rows[] = $row;
foreach($rows as $row)
{
$gname = $row->name;
$gid = $row->id;
echo ‘

’;
$history = mysql_query(‘SELECT h.userid,h.itemid,h.finaltotal FROM scores h, items g WHERE h.itemid = ‘.$gid.’’);
$rows = array();
while($row = mysql_fetch_array($history))
$rows[] = $row;
foreach($rows as $row)
{
$userid = $row->userid;
echo ‘’;
}
}
echo ‘
’.$gname.’
’.$firstname.’ ‘.$lastname.’
’;

items table

id name
1 Test1
2 Lab
3 Quiz
4 Praticals
5 Seminar

history table

id userid itemid finaltotal
1 5 1 56%
2 5 2 72%
3 5 3 23%
4 5 4 23%
5 5 5 62%

6 3 1 82%
7 3 2 77%
8 3 3 66%
9 3 4 67%
10 3 5 50%

11 8 1 42%
12 8 2 77%
13 8 3 65%
14 8 4 60%
15 8 5 89%

I need the out put like in a tabular form

             Test1    Lab      Quiz      Praticals    Seminar

(userid) 5 56% 72% 23% 23% 62%
3 82% 77% 66% 67% 50%
8 42% 77% 65% 60% 89%

Sponsor our Newsletter | Privacy Policy | Terms of Service