There are 2 ways to achieve this result:
1- Group your records by name and date then re-query the ids for each record. But this is not an efficient way. If you have hundreds of distinct name/date you will have to process hundreds of queries.
2- Query all the results sorted by name and date, and write the datas on name/date change.
Here is the second way.
This is done with mssql cause I've it under my hand but this works the same with MySQL
--8<--- BEGIN CODE --8<---
<?php
$conn = mssql_connect(SERVER,UID,PWD);
mssql_select_db("vae_dev",$conn);
$sql = "
SELECT t_id,
t_name,
t_date
FROM php_test
WHERE t_check = 0
ORDER BY t_name,t_date";
$qry = mssql_query( $sql, $conn );
$ids= array();
while ( $row = mssql_fetch_array( $qry ) ) {
if ( $name != $row["t_name"] || $date != $row["t_date"] ) {
// This is a new line so we write the link
if ( count($ids) > 0 ) {
printf( "<A HREF=\"displayAllRows.php?ids=%s\">%s %s</A><br>\n",
implode($ids,","),
$name,
$date
) ;
}
$name = $row["t_name"];
$date = $row["t_date"];
$ids = array();
}
$ids[] = $row["t_id"];
}
// Don't forget the last line
if ( count($ids) > 0 ) {
printf( "<A HREF=\"displayAllRows.php?ids=%s\">%s %s</A>\n",
implode($ids,","),
$name,
$date
) ;
}
mssql_close($conn);
?>
--8<--- END CODE --8<---
Hope this helps