Query Manipulation after getting a result set

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ocptime
Forum Newbie
Posts: 11
Joined: Thu Mar 18, 2004 4:59 am
Location: Trivandrum, Kerala, India

Query Manipulation after getting a result set

Post by ocptime »

my query result is this
#######################
TestName | Count | Result

PHP 1 Passed

PHP 1 Failed

Test Your IQ? 2 Passed

Test Your IQ? 5 Failed
######################
i want to manipulate the result so that i can show it like this

############################
TestName Count PassCount FailCount

PHP 2 1 1

Test Your IQ? 7 2 5

#############################
How can i do this

Pls Help

Thanx in Advance
[/b][/php_man]
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

What does the code you have now look like?
ocptime
Forum Newbie
Posts: 11
Joined: Thu Mar 18, 2004 4:59 am
Location: Trivandrum, Kerala, India

Post by ocptime »

$sql="SELECT t.title, count(r.testId) as count, r.result FROM qb_test_report AS r, qb_test AS t
WHERE r.status = 'Completed' AND t.testId = r.testId
GROUP BY r.result, t.testId ORDER BY t.title" ;
ocptime
Forum Newbie
Posts: 11
Joined: Thu Mar 18, 2004 4:59 am
Location: Trivandrum, Kerala, India

Post by ocptime »

Here is the complete solutions

$sql="SELECT t.title, count(r.testId) as count, r.result
FROM qb_test_report AS r, qb_test AS t
WHERE r.status = 'Completed' AND t.testId = r.testId
GROUP BY r.result, t.testId ORDER BY t.title" ;

$rs = $db->Execute($sql);

if($rs->RecordCount()>0){
while($row = $rs->FetchRow()){
${$row['result']} = $row['count'];
$row = $rs->FetchRow();
${$row['result']} = $row['count'];
$total = $Passed + $Failed ;

}


Bye
Post Reply