tags:

views:

30

answers:

1

I have some data like this :

1   TC1 PASS
2   TC2 FAIL
3   TC3 INCONC
4   TC1 FAIL
5   TC21    FAIL
6   TC4 PASS
7   TC3 PASS
8   TC2 FAIL
9   TC1 TIMEOUT
10  TC21    FAIL

If I try the below code :

<?php

   mysql_connect("localhost", "root", "pop") or die(mysql_error());
   mysql_select_db("jpd") or die(mysql_error());
   $oustanding_fails = mysql_query("SELECT * FROM SELECT_PASS ") or die(mysql_error());  

   $resultSetArray = array();
   $platform;

   while($row1 = mysql_fetch_array( $oustanding_fails )) {
     if(trim($row1['TESTCASE']) <> trim($platform))   {
       echo $row1['TESTCASE']."-"; 
       $platform = $row1['TESTCASE'];
     }

     echo $row1['RESULT'] ."<br>";
} ?>

...to get a result like this :

TC1
   PASS
   FAIL
   TIMEOUT
TC2
   FAIL
   FAIL
TC3
   INCONC
   PASS
TC4
   PASS

...and so on. I am unable to get the result I want LIKE ABOVE - any ideas where exactly I am making mistake?

A: 

change your sql to:

SELECT * FROM SELECT_PASS ORDER BY TESTCASE
Dan
Can you please explain me why this worked? I really did not think that ordering will give me the result I want. Is there any debugger for any SQL database to actually see how it is fetching the results and the whole process till it displays the results? or any PHP debugger ?
JPro
Ordering the results is very common across any database. You don't need a debugger. Just use something like MySQLWorkbench to create SQL statements and evaluate the results without needing to include PHP. Then when you are satisfied with the SQL, paste it into your PHP code.
Dan