maliary Posted July 23, 2007 Share Posted July 23, 2007 The code below works fantastic with that simple SQL query, I've made some changes to the query to thus :- $depts = $db->Execute("SELECT $dbtable.serial_value,$dbtable.type,$dbtable.test_time,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable INNER JOIN $table ON ($table.group_id = $dbtable.group_id) WHERE $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"); It now gives diffrent out put as Group: C Piccadilly Piccadilly Group: C Group: E Group: C Group: E Group: C Group: E Group: C Group: E Ashton Oldham Instead of : Group: C Piccadilly Piccadilly Group: E Ashton Oldham What do I have to change here to make it work like it should? <?php echo "<table width=250 align=center cellspacing=0 cellpadding=0>\n"; // Set initial group values $lastgroup = ''; // Query database $sql = "SELECT * FROM table ORDER BY name ASC "; $res = mysql_query($sql) or die(mysql_error()); while ($rows = mysql_fetch_assoc($res)){ // Print Group header if ($rows['name'] != $lastgroup) { // Print Group Name echo "<tr> <td colspan=2 align=left><strong>Group: ".$rows['name']."</strong></td> </tr>\n"; } // Print Database Details echo "<tr> <td width=50> </td> <td width=200 align=center>".$rows['parameters']."</td> </tr>\n"; // Reset group values $lastgroup = $rows['name']; } echo "</table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/ Share on other sites More sharing options...
sasa Posted July 23, 2007 Share Posted July 23, 2007 change line if ($rows['name'] != $lastgroup) { to if ($rows['group_id'] != $lastgroup) { and $lastgroup = $rows['name']; to $lastgroup = $rows['group_id']; Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-305471 Share on other sites More sharing options...
maliary Posted July 23, 2007 Author Share Posted July 23, 2007 Thanks, Sorry i didn't update that code. I've changed it but the display is still the same. Here is the updated code <?php echo "<table width=250 align=center cellspacing=0 cellpadding=0>\n"; // Set initial group values $lastgroup = ''; // Query database $sql = "SELECT $dbtable.serial_value,$dbtable.type,$dbtable.test_time,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable INNER JOIN $table ON ($table.group_id = $dbtable.group_id) WHERE $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"; $res = mysql_query($sql) or die(mysql_error()); while ($rows = mysql_fetch_assoc($res)){ // Print Group header if ($rows['group_id'] != $lastgroup) { // Print Group Name echo "<tr> <td colspan=2 align=left><strong>Group: ".$rows['name']."</strong></td> </tr>\n"; } // Print Database Details echo "<tr> <td width=50> </td> <td width=200 align=center>".$rows['parameters']."</td> </tr>\n"; // Reset group values $lastgroup = $rows['group_id]; } echo "</table>\n"; ?> Should I give you a dump of the two tables? Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-305473 Share on other sites More sharing options...
Barand Posted July 23, 2007 Share Posted July 23, 2007 Where is "$rows['parameters']" coming from? Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-305630 Share on other sites More sharing options...
maliary Posted July 24, 2007 Author Share Posted July 24, 2007 Sorry about that, <?php echo "<table width=250 align=center cellspacing=0 cellpadding=0>\n"; // Set initial group values $lastgroup = ''; // Query database $sql = "SELECT $dbtable.serial_value,$dbtable.type,$dbtable.test_time,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable INNER JOIN $table ON ($table.group_id = $dbtable.group_id) WHERE $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"; $res = mysql_query($sql) or die(mysql_error()); while ($rows = mysql_fetch_assoc($res)){ // Print Group header if ($rows['group_id'] != $lastgroup) { // Print Group Name echo "<tr> <td colspan=2 align=left><strong>Group: ".$rows['group_id]."</strong></td> </tr>\n"; } // Print Database Details echo "<tr> <td width=50> </td> <td width=200 align=center>".$rows['name']."</td> </tr>\n"; // Reset group values $lastgroup = $rows['group_id]; } echo "</table>\n"; ?> That's the way it should be. Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306033 Share on other sites More sharing options...
maliary Posted July 24, 2007 Author Share Posted July 24, 2007 Actually this is the entire code segment: Am using the first while loop because I need to print out the $rval[$counter] array. <?php echo "<table width=250 align=center cellspacing=0 cellpadding=0>\n"; // Set initial group values $lastgroup = ''; $x = 0; while ($x < $cols) { // Query database $sql = "SELECT $dbtable.serial_value,$dbtable.type,$dbtable.test_time,$dbtable.group_id,$table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable INNER JOIN $table ON ($table.group_id = $dbtable.group_id) WHERE $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"; $res = mysql_query($sql) or die(mysql_error()); while ($rows = mysql_fetch_assoc($res)){ // Print Group header if ($rows['group_id'] != $lastgroup) { // Print Group Name echo "<tr> <td colspan=2 align=left><strong>Group: ".$rows['group_id]."</strong></td> </tr>\n"; } // Print Database Details echo "<tr> <td width=50> </td> <td width=200 align=center>".$rows['name']."</td> <td width=200 align=center>".$rval[$counter]."</td> </tr>\n"; // Reset group values $lastgroup = $rows['group_id]; } } echo "</table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306058 Share on other sites More sharing options...
Barand Posted July 24, 2007 Share Posted July 24, 2007 can you dump some test data in an attachment so we can see what's happening? Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306078 Share on other sites More sharing options...
maliary Posted July 24, 2007 Author Share Posted July 24, 2007 Database variables stand for: $dbtable = 'care_test_findings_chemlab'; $table = 'care_test_param'; [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306084 Share on other sites More sharing options...
maliary Posted July 24, 2007 Author Share Posted July 24, 2007 I am not sure but is what I have attached ok? The out put is this way where the batch_nr is 62070. This is erroneous as it should be printing out this way Group: Endocrine/Tumor_Marker 226 2 THYROID ANTIBODIES Group: Serology 249 1 VIRAL LOAD DNA Group: Endocrine/Tumor_Marker 119 - ACETYLLCHOLINE RECEPTOR ANTIBODY 128 - CA 125 129 - CA 15.3 130 - CA 19-9 132 - CEA (CARCINOEMBRONIC ANTIGEN) 141 - DHEAS HORMONE 152 - FREE PSA 153 - FREE T3 TEST 154 - FREE T4 TEST 155 - FSH TEST 186 - LH 195 - MICROSOMALTHYRO AB 198 - PARATHYROID HORMONE 223 - THYROID FUNCTION TESTS 226 2 THYROID ANTIBODIES Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology 120 - AMOEBIC HAEMOGUTINATION 127 - BRUCELLA TEST 131 - CD4/CD8 135 - CMV ANTIBODY TEST 170 - HEPATITIS C VIRUS 171 - HERPES SIMPLEX 174 - HIV SCREENING (ELISA) 175 - HEPATITIS B COR IGM 194 - MEASLES ANTIBODIES 196 - MUMPS ANTIBODIES 206 - RHEUMATOID FACTOR 222 - TB SEROLOGY 230 - TPHA FTA 236 - VDRL 237 - WEIL FELIX 240 - WIDAL TEST(WITH TITRES) 249 1 VIRAL LOAD DNA Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Group: Endocrine/Tumor_Marker Group: Serology Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306098 Share on other sites More sharing options...
Barand Posted July 24, 2007 Share Posted July 24, 2007 Changed code slightly to <?php $cnx = mysql_connect('localhost'); mysql_select_db('test3'); $dbtable = 'care_test_findings_chemlab'; $table = 'care_test_param'; $batch_nr = 62070; echo "<table width=250 align=center cellspacing=0 cellpadding=0>\n"; $cols=1; $x = 0; while ($x++ < $cols) { // Set initial group values $lastgroup = ''; // <--- muved inside the while loop // Query database $sql = "SELECT $dbtable.serial_value,$dbtable.type,$dbtable.test_time,$dbtable.group_id, $table.name,$table.nr,$table.normals,$table.msr_unit FROM $dbtable INNER JOIN $table ON ($table.group_id = $dbtable.group_id) WHERE $dbtable.job_id = '$batch_nr' ORDER BY group_id ASC"; $res = mysql_query($sql) or die(mysql_error()); while ($rows = mysql_fetch_assoc($res)){ // Print Group header if ($rows['group_id'] != $lastgroup) { // Print Group Name echo "<tr> <td colspan=3 align=left><strong>Group: ".$rows['group_id']."</strong></td> </tr>\n"; } // Print Database Details echo "<tr> <td width=50> </td> <td width=200 align=center>".$rows['name']."</td> <td width=200 align=center>".$rval[$counter]."</td> </tr>\n"; // Reset group values $lastgroup = $rows['group_id']; } } echo "</table>\n"; ?> -->[pre] Group: Endocrine/Tumor_Marker ACETYLLCHOLINE RECEPTOR ANTIBODY CA 125 CA 15.3 CA 19-9 CEA (CARCINOEMBRONIC ANTIGEN) DHEAS HORMONE FREE PSA FREE T3 TEST FREE T4 TEST FSH TEST LH MICROSOMALTHYRO AB PARATHYROID HORMONE THYROID FUNCTION TESTS THYROID ANTIBODIES Group: Serology AMOEBIC HAEMOGUTINATION BRUCELLA TEST CD4/CD8 CMV ANTIBODY TEST HEPATITIS C VIRUS HERPES SIMPLEX HIV SCREENING (ELISA) HEPATITIS B COR IGM MEASLES ANTIBODIES MUMPS ANTIBODIES RHEUMATOID FACTOR TB SEROLOGY TPHA FTA VDRL WEIL FELIX WIDAL TEST(WITH TITRES) VIRAL LOAD DNA [/pre] Not sure where $rval[$counter] comes from Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306584 Share on other sites More sharing options...
maliary Posted July 25, 2007 Author Share Posted July 25, 2007 Hi, I had made refrence to the $rval[counter] in the mail. Its supposed to loop and display the array details.However It cannot loop through all. Quote Link to comment https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-307002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.