Jump to content

[SOLVED] Display tweak


maliary

Recommended Posts

Hi,

 

I want to make a display from a table in the following format

 

GroupName1

fruit1

fruit2

fruit3

GroupResults1

 

GroupName2

fruit1

fruit2

fruit3

GroupResults2

 

This is my code:below:

Where can I tweak it?

 


$sql ="SELECT DISTINCT $dbtable.serial_value,$dbtable.type,$$dbtable.group_id,$dbtable.groupresults,table.name,$table.nr,$table.normals,$table.msr_unit  FROM $dbtable INNER JOIN $table ON $dbtable.group_id = $table.group_id WHERE  $dbtable.job_id = '$batch_nr' ORDER BY group_id DESC";
$res = mysql_query($sql) or die(mysql_error());

while ($rows = mysql_fetch_assoc($res)){


    if ($rows['group_id'] != $lastgroup) {
    // Print Group Name
    echo "<tr>
            <td colspan=3 align=left><strong>Group: ".$rows['group_id']."</strong></td>
          </tr>\n";
    }

   echo "<tr>
            <td width=50> </td>
             <td width=200 height=25 align=center>".$rows['name']."</td>

  $lastgroup = $rows['group_id'];

}


 

 

 

 

 

 

 

Link to comment
Share on other sites

 

 

From this code i get the following output:

 


$sql ="SELECT DISTINCT $dbtable.serial_value,$dbtable.type,$$dbtable.group_id,$dbtable.groupresults,table.name,$table.nr,$table.normals,$table.msr_unit  FROM $dbtable INNER JOIN $table ON $dbtable.group_id = $table.group_id WHERE  $dbtable.job_id = '$batch_nr' ORDER BY group_id DESC";
$res = mysql_query($sql) or die(mysql_error());

while ($rows = mysql_fetch_assoc($res)){


    if ($rows['group_id'] != $lastgroup) {
    // Print Group Name
    echo "<tr>
            <td colspan=3 align=left><strong>Group: ".$rows['group_id']."</strong></td>
          </tr>\n";
    }

   echo "<tr>
            <td width=50> </td>
             <td width=200 height=25 align=center>".$rows['name']."</td><tr>";

  echo"<tr><td width=50>".$rows['groupresults']."</td></tr>"; 

  $lastgroup = $rows['group_id'];

}

groupname
fruitname
groupresults
fruitname2
groupresults


while it should be like:

groupname
fruitname
fruitname2
groupresults






 

 

 

 

 

 

Link to comment
Share on other sites

 

 

Am sorry I've been very vague on this.

 

This is what I would like:

 

What i mean is this,

 

The code currently displays database out put in this format without the part I have commented out

 

GroupName : Flower

rose

petal

 

GroupName : Animal

goat

cow

 

 

I would like to display a field group result at the end of each group.

 

Thus:

 

GroupName : Flower

rose

petal

Results

 

 

GroupName : Animal

goat

cow

Results

 

How can I do this? Its just a display thing.

 

$sql ="SELECT DISTINCT $dbtable.serial_value,$dbtable.type,$dbtable.results,$dbtable.group_id,$dbtable.groupresults,table.n  ame,$table.nr,$t  able.normals,$table.msr_unit  FROM $dbtable INNER JOIN $table ON $dbtable.group_id = $table.group_id WHERE  $dbtable.job_id = '$batch_nr' ORDER BY group_id DESC";
$res = mysql_query($sql) or die(mysql_error());

while ($rows = mysql_fetch_assoc($res)){


    if ($rows['group_id'] != $lastgroup) {
    // Print Group Name
    echo "<tr>
            <td colspan=3 align=left><strong>Group: ".$rows['group_id']."</strong></td>
          </tr>\n";
    }

   echo "<tr>
            <td width=50> </td>
             <td width=200 height=25 align=center>".$rows['name']."</td><tr>";

  # the results which should be at the bottom of every group 
//echo "<tr>
            //<td width=50> </td>
             //<td width=200 height=25 //align=center>".$rows['results']."</td><tr>";

  $lastgroup = $rows['group_id'];

}  

[code=php:0]  

 

Link to comment
Share on other sites

<?php

$sql ="SELECT DISTINCT $dbtable.serial_value,$dbtable.type,$dbtable.results,$dbtable.group_id,$dbtable.groupresults,table.n  ame,$table.nr,$t  able.normals,$table.msr_unit  FROM $dbtable INNER JOIN $table ON $dbtable.group_id = $table.group_id WHERE  $dbtable.job_id = '$batch_nr' ORDER BY group_id DESC";
$res = mysql_query($sql) or die(mysql_error());

while ($rows = mysql_fetch_assoc($res)){

    //New Group Name
    if ($rows['group_id'] != $lastgroup) {

        //Display last subtotal if not first group
        if ($lastgroup) {
            echo "<tr>
                    <td width=\"50\"> </td>
                    <td width=\"200\" height=\"25\" align=\"center\">$subtotal</td>
                  </tr>";
        }

        //Reset the subtotal
        $subtotal = 0;

        //Print the group name
        echo "<tr>
                <td colspan=2 align=left><strong>Group: ".$rows['group_id']."</strong></td>
              </tr>\n";
    }

    //Display the record
    echo "<tr>
            <td width=50> </td>
            <td width=200 height=25 align=center>".$rows['name']."</td>
          <tr>";

    //Add to subtotal
    $subtotal++;

    //Set the lastgroup value
    $lastgroup = $rows['group_id'];

}

//Show the last subtotal row
echo "<tr>
        <td width=\"50\"> </td>
        <td width=\"200\" height=\"25\" align=\"center\">$subtotal</td>
      </tr>";
?>

Link to comment
Share on other sites

 

Thanks a lot, I really appreciate your help.

 

The code doesn't display the results part. It only displays for one result at the bottom of the wrong group. 

I've added an extra line of code next to $subtotal

 

<?php

$sql ="SELECT DISTINCT $dbtable.serial_value,$dbtable.type,$dbtable.results,$dbtable.group_id,$dbtable.groupresults,table.n  ame,$table.nr,$t  able.normals,$table.msr_unit  FROM $dbtable INNER JOIN $table ON $dbtable.group_id = $table.group_id WHERE  $dbtable.job_id = '$batch_nr' ORDER BY group_id DESC";
$res = mysql_query($sql) or die(mysql_error());

while ($rows = mysql_fetch_assoc($res)){

    //New Group Name
    if ($rows['group_id'] != $lastgroup) {

        //Display last subtotal if not first group
        if ($lastgroup) {
            echo "<tr>
                    <td width=\"50\"> </td>
                    <td width=\"200\" height=\"25\" align=\"center\">$subtotal</td>
                   <td width=\"200\" height=\"25\" align=\"center\">Results: $rows['notes']</td> // New line of code here
                  </tr>";
        }

        //Reset the subtotal
        $subtotal = 0;

        //Print the group name
        echo "<tr>
                <td colspan=2 align=left><strong>Group: ".$rows['group_id']."</strong></td>
              </tr>\n";
    }

    //Display the record
    echo "<tr>
            <td width=50> </td>
            <td width=200 height=25 align=center>".$rows['name']."</td>
          <tr>";

    //Add to subtotal
    $subtotal++;

    //Set the lastgroup value
    $lastgroup = $rows['group_id'];

}

//Show the last subtotal row
echo "<tr>
        <td width=\"50\"> </td>
        <td width=\"200\" height=\"25\" align=\"center\">$subtotal</td>
         <td width=\"200\" height=\"25\" align=\"center\">Results: $rows['notes']</td> // New line of code here
      </tr>";
?>





Link to comment
Share on other sites

Ok, you need to be specific by what you mean by "results". I assumed you menat the number of records, but now you are displaying $rows['notes']. By my logic that would only show the notes for the last record in a group. So what, exactly, do you want the results entry to be?

Link to comment
Share on other sites

 

It only displays the $rows['notes'] once under the wrong group. For the other groups that get displayed no $rows['notes'] are displayed.

 

Let me attach a dump of the two tables.

 

This is how it prints out

 

Group: Serology

  CD4/CD8 9

  VIRAL LOAD DNA 1

  Notes larvae seen in alchohol content 17

 

Group: Endocrine/Tumor_Marker

  THYROID ANTIBODIES 2

  Notes 15

 

[attachment deleted by admin]

Link to comment
Share on other sites

 

It only displays the $rows['notes'] once under the wrong group. For the other groups that get displayed no $rows['notes'] are displayed.

 

Let me attach a dump of the two tables.

 

This is how it prints out

 

Group: Serology

  CD4/CD8 9

  VIRAL LOAD DNA 1

  Notes larvae seen in alchohol content 17

 

Group: Endocrine/Tumor_Marker

  THYROID ANTIBODIES 2

  Notes 15

 

How should it print out?

Link to comment
Share on other sites

It should be this way,

 

Group: Serology

  CD4/CD8 9

  VIRAL LOAD DNA 1

  Notes tests seen in serology 17

 

Group: Endocrine/Tumor_Marker

  THYROID ANTIBODIES 2

  Notes   larvae seen in alchohol content 15

 

The correct $rows['notes'] output as per the group.

 

Link to comment
Share on other sites

The notes you print are from the new group record you have just read, but you output them at the end of the previous group. Store the notes field in, say, $savenotes, and output that when you start a new group.

 

After you exit the loop, you then have to output the saved notes and total for the final group.

Link to comment
Share on other sites

Here's revised code that should work for your needs:

<?php

$sql ="SELECT DISTINCT $dbtable.serial_value,$dbtable.type,$dbtable.results,$dbtable.group_id,$dbtable.groupresults,table.n  ame,$table.nr,$t  able.normals,$table.msr_unit  FROM $dbtable INNER JOIN $table ON $dbtable.group_id = $table.group_id WHERE  $dbtable.job_id = '$batch_nr' ORDER BY group_id DESC";
$res = mysql_query($sql) or die(mysql_error());

while ($rows = mysql_fetch_assoc($res)){

    //New Group Name
    if ($rows['group_id'] != $lastgroup) {

        //Display last notes value if exists
        if ($lastnotes) {
            echo "<tr>
                    <td width=\"50\"> </td>
                    <td width=\"200\" height=\"25\" align=\"center\">$subtotal</td>
                   <td width=\"200\" height=\"25\" align=\"center\">Results: $lastnotes</td> // New line of code here
                  </tr>";
        }

        //Set the lastnotes value
        $lastnotes = $rows['notes'];

        //Print the group name
        echo "<tr>
                <td colspan=2 align=left><strong>Group: ".$rows['group_id']."</strong></td>
              </tr>\n";
    }

    //Set the lastgroup value
    $lastgroup = $rows['group_id'];

    //Display the record
    echo "<tr>
            <td width=50> </td>
            <td width=200 height=25 align=center>".$rows['name']."</td>
          <tr>";

}

//Show the last notes value
echo "<tr>
        <td width=\"50\"> </td>
        <td width=\"200\" height=\"25\" align=\"center\">$subtotal</td>
         <td width=\"200\" height=\"25\" align=\"center\">Results: $lastnotes</td> // New line of code here
      </tr>";
?>

Link to comment
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.