...

View Full Version : formatting mysql result



che_anj
04-03-2008, 05:12 PM
hello I just want to ask anybody who has an idea with regards in formating the display of mysql result.

Attached files are the format(report.jpg) which I want to change to another format (reportformat.jpg)






Thanks a lot..

Fumigator
04-03-2008, 05:17 PM
Use a control break (http://en.wikipedia.org/wiki/Control_break) to hold off outputing record until you've fetched all of the rows for that record.

che_anj
04-03-2008, 05:20 PM
do u have any example? of control break?


the structure of my table is below..
event_id | action_type | updatedby| updatedlast`
1 | 15 | 2 | date
2 | 13 | 2 | date
3 | 15 | 1 | date
4 | 18 | 1 | date
5 | 19 | 1 | date


event id is the primary key.

Fumigator
04-03-2008, 05:31 PM
This will echo each unique last_name in table1. You'll need to flip it a bit to print the previous record info when the name changes.



$query = (SELECT * FROM table1 ORDER BY last_name);
$result = mysql_query($query);
if (!$result) {
die ("Query error in $query<br />" . mysql_error());
}

$prevLastName = " ";
for ($i = 0; $i < mysql_num_rows($result); $i++) {
$rowInfo = mysql_fetch_assoc($result);
if ($rowInfo['last_name'] > $prevLastName) {
echo $rowInfo['last_name']."<br />";
$prevLastName = $rowInfo['last_name'];
}
}

Bahamut
04-03-2008, 05:51 PM
<?php
$sql1 = "SELECT updatedby FROM eventss GROUP BY updatedby";
$res1 = mysql_query($sql1);
while ($row1 = mysql_fetch_assoc($res1)) {
echo "<p>=by=".$row1['updatedby']."=by= ";
$sql2 = "SELECT action_type FROM eventss WHERE updatedby = $row1[updatedby]";
$res2 = mysql_query($sql2);
while ($row2 = mysql_fetch_assoc($res2)) {
echo " =action=".$row2['action_type']."=action= ";
}
}
mysql_close($link);


?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum