I need to display the sections of a given product in one cell.
The table in the mysql looks like this:
id| sections_id | products_id | date | starttime | endtime|
1 | 2155 | 146 | 2004-05-22 | 09:00 | 18:00 |
2 | 2155 | 146 | 2004-05-23 | 09:00 | 18:00 |
3 | 2156 | 82 | 2004-08-01 | 09:00 | 18:00 |
4 | 2156 | 82 | 2004-08-08 | 09:00 | 18:00 |
5 | 2156 | 82 | 2004-08-15 | 09:00 | 18:00 |
6 | 2157 | 96 | 2004-07-21 | 09:00 | 18:00 |
6 | 2158 | 155 | 2004-10-30 | 09:00 | 18:00 |
On the "viewsections.php" . I want to list all the dates, starttime , endtime that belong to one section in a single row. for example, the output i want is:
products_id | sections_id | dates | start | end |
--------------------------------------------------------------------------------- | | 2004-05-22 | 09:00 | 18:00 |
146 | 2155 | 2004-05-23 | 09:00 | 18:00 |
| | 2004-08-01 | 09:00 | 18:00 |
82 | 2156 | 2004-08-08 | 09:00 | 18:00 |
| | 2004-08-15 | 09:00 | 18:00 |
96 | 2157 | 2004-07-21 | 09:00 | 18:00 |
155 | 2158 | 2004-10-30 | 09:00 | 18:00 |
The code that I have as of lists each row on a new line. I have pasted the code below.
This is the first time I am posting a thread. Hope this information is useful.
echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"600\">";
echo "<tr>";
echo "<td>Section ID</td>";
echo "<td>Class Name</td>";
echo "<td>Date</td>";
echo "<td>Start Time</td>";
echo "<td>End Time</td>";
echo "<td>Edit Section</td>";
echo "<td>Delete Section</td>";
echo "</tr>";
$rs_sections_query = mysql_query("SELECT pd.products_name, psd.products_id, psd.sections_id, psd.date, psd.start_time, psd.end_time FROM products_sections_datetimes psd, products_description pd WHERE pd.products_id = psd.products_id ");
$rs_grp_section_id_query = mysql_query(" SELECT DISTINCT(sections_id) FROM products_sections_datetimes ");
while ($row_grp_section_id = mysql_fetch_assoc($rs_grp_section_id_query)){
$distinct_section_id = $row_grp_section_id["sections_id"];
while ($row = mysql_fetch_assoc($rs_sections_query)) {
$sectionid = $row["sections_id"];
$productid = $row["products_id"];
$productname = $row ["products_name"];
$date = $row["date"];
$start_time = $row["start_time"];
$end_time = $row["end_time"];
if($distinct_section_id == $sectionid){
echo "<tr>";
}
}
echo "<td align=\"left\" valign=\"top\">" . $sectionid ."</td>";
echo "<td align=\"left\" valign=\"top\">"; echo $productname . "</td>"; echo "<td align=\"left\" valign=\"top\">" . $date ."</td>";
echo "<td align=\"left\" valign=\"top\">" . $start_time ."</td>"; echo "<td align=\"left\" valign=\"top\">" . $end_time ."</td>";
echo "</tr>";
}
}
echo "</table>";
?>
I am completely stumped. Thanks in advance for your suggestions.