Jump to content

php display solution required


maliary

Recommended Posts

Hi,

 

I have a table in mysql with 2 columns.group name and the group parameters.

There is one group name with several group parameters.

 

I would like to retrieve this from the database such that it will only display one group and the other several parameters in it,for all the diffrent groups.

 

does anyone know how i can go about this?

 

Maliary

Link to comment
https://forums.phpfreaks.com/topic/46898-php-display-solution-required/
Share on other sites

of course

 

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

 

Ray

If you ran the above code, as I did on on of my tables, you'd see output like this.

[pre]Group: C

  Piccadilly

  Piccadilly

Group: E

  Ashton

  Oldham

  Hyde

  Ashton

  Oldham

Group: N

  Middleton

  Rochdale

  Bolton

  Rochdale

  Bury

Group: S

  Stockport

  Altrincham

  Wythenshawe

Group: W

  Leigh

  Wigan

  Wigan [/pre]

 

So

a ) why bother posting if you don't accept the solution

 

b ) I closed your second post on this same question before you waste anyone else's time (read the forum rules regarding double posting)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.