Output MySQL result to formatted table (advanced)

Hi,

I am trying to format the output of a MySQL query into a nice table (without duplicates of same data) but having issues.

I have a MySQL query which looks like the following:

Object_id Object_name sub_id person amount
1 OBJ 1 2 Person A 167.25
1 OBJ 1 3 Person B -41.81
1 OBJ 1 4 Person C 797.84
1 OBJ 1 4 Person C 35.64
2 OBJ 2 5 Person A 202.72
2 OBJ 2 5 Person B 799.93

The output I am trying to get to is
OBJ 1
Person A 167.25
Person B -41.81
Person C 797.84
Person C 35.64
OBJ
Person A 202.72
Person B 799.93

Any ideas?

Hello Tinks… am new to this forum too, i just joined on friday but am also here today looking for help on the code segment of my page but when i saw ur post, i tot i might be of help on that one before i post whats really burgging me for the code gurus to crack for me… i would hv recomended u an sql query string that is able to query based on two search parameters but for simplicity, i will show u the simple way. from your table you should make use of two query strings i.e

$query1 = mysql_query("SELECT * FROM tablename WHERE Object_id=1");
$query2 = mysql_query("SELECT * FROM tablename WHERE Object_id=2");

?>
<tr>OOBJ 1</tr>
	<tr><td>Object_name</td><td>	SUb_id</td></tr>
<?
while($row = mysql_fetch_array($query1){
?>
<tr>
<td><?= $row['Object_name']?></td>
<td><?= $row['sub_id']?></td>
</tr>
<?	
}
//another while for the second print containing OBJ 2
<tr>OOBJ 2</tr>
	<tr><td>Object_name</td><td>	SUb_id</td></tr>
<?
while($row2 = mysql_fetch_array($query2){
?>
<tr>
<td><?= $row2['Object_name']?></td>
<td><?= $row2['sub_id']?></td>
</tr>
<?	
}

i just used note pad to write this but i hope it works, even not so, i hope you get the scope of my idea…
gud luck to you…

Sponsor our Newsletter | Privacy Policy | Terms of Service