Jump to content

Recommended Posts

 

 

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/61374-grouped-display/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-305473
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306033
Share on other sites

 

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";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306058
Share on other sites

 

 

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




Link to comment
https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306098
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/61374-grouped-display/#findComment-306584
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.