Jump to content

How do I subtotal/group a list??


dazzathedrummer

Recommended Posts

Hi,

 

I have a very basic page that puts a list of dates from a mysql database into a list in order of date like this...

 

echo'
<h1>Gigs</h1>
<table width=\"400\" height=\"200\" >';
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{echo 
"<form action=\"giglist_private_update.php\" method=\"post\">".
"

<tr>
<td style=\"height:80px; width:80px;\"valign=\"top\">
<img height=\"79px\" width=\"79px\" valign=\"top\" alt=\"calendarpic\"  style=\"position:absolute; vertical-align:top; z-index:1;\" src=\"calpics/{$row['background']}.png\"/>
<img height=\"79px\" width=\"79px\" valign=\"top\" alt=\"calendarpic1\"  style=\"position:absolute; vertical-align:top; z-index:2;\" src=\"calpics/{$row['day']}.png\"/>
<img height=\"79px\" width=\"79px\" valign=\"top\" alt=\"calendarpic2\"  style=\"position:absolute; vertical-align:top; z-index:3;\" src=\"calpics/{$row['month']}.png\"/></td>".
"<td colspan=\"3\"><font size=\"4\"><strong>{$row['gl_venue']} {$row['gl_city']}, {$row['gl_postcode']} </td><td>{$row['pf']}{$row['publish']}{$row['unavailable']}</td>".
"<td colspan=\"2\"><a href=\"http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q={$row['gl_postcode']}\">Map</a></td><td>".
"<form action=\"giglist_private_entry.php\" method=\"post\">".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_date\" value=\"{$row['gl_date']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_venue\" value=\"{$row['gl_venue']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_postcode\" value=\"{$row['gl_postcode']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_city\" value=\"{$row['gl_city']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_phone\" value=\"{$row['gl_phone']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_contact\" value=\"{$row['gl_contact']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_net\" value=\"{$row['gl_net']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_comments\" value=\"{$row['gl_comments']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_text\" value=\"{$row['gl_text']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_pf\" value=\"{$row['gl_pf']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_id\" value=\"{$row['gl_id']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_unavailable\" value=\"{$row['gl_unavailable']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_next_gig\" value=\"{$row['gl_next_gig']}\"></td>".
"<td display=\"none\"><td><input type=\"hidden\" name=\"gl_publish\" value=\"{$row['gl_publish']}\"></td>".
"<td><input type=\"submit\" value=\"Details\">"
;


}
echo '<tr style=\"height:40px\"></tr></tr></table><br><br>';

 

The hidden fields post the details from the query to memory so they can be displayed on an 'edit' page.

 

How do I go about grouping this list by month??

 

My instincts are telling me to create a field in the mysql query that returns the month (month(gl_date) with a case statement for '1='January' etc).

Then what do I do.......is it an array of arrays? how do I code that?

Link to comment
Share on other sites

You can directly select the monthname instead - http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_monthname

 

You would also use an order by gl_date term in the query to order the rows the way you want. To output a new monthname heading when it changes in the data, see this post - http://www.phpfreaks.com/forums/index.php?topic=349740.msg1650897#msg1650897

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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