Jump to content

Displaying Grouped Data Correctly


dbnorton

Recommended Posts

Ok I have some data that I would like to have grouped by date. There are dates that have multiple entries for the same date.  I would like to have that data listed under one date. I would like it to look like this

 

Date

        Location    Weather

        Location    Weather

Date

        Location      Weather

 

Here is the code I have so far and it lists the data by date but only the data for first date in the table.  If there is data listed for the same date but different location it will not list that data.  What am I missing.  Any help would be great.

!

<?php

// Connect to server and select database.

include ("opendb.php");

$tbl_name="dbnwaterfowl";

 

$sql="SELECT huntDate, huntLocation, huntWeather, waterfowlSpecies, waterfowlNumberKilled, waterfowlBandedNumber, DATE_FORMAT(huntDate,'%m %d, %Y') FROM dbnwaterfowl GROUP BY `huntDate` ORDER BY `huntDate` ASC";

$result=mysql_query($sql);

?>

<td>

  <p> </p>

  <table width="100%" border="2" cellpadding="1" cellspacing="0" bordercolor="#FA6103" bgcolor="#FFFFFF">

<tr>

<td colspan="7"><div align="center">

  <p><img src="images/hl-logo.jpg" /></p>

  <p align="center"><strong><a href="login.php">Login</a> | <a href="insert.php">Log Hunt</a> | <a href="logout.php">Logout</a></strong></p>

</div></td>

</tr>

 

<tr>

<td align="center" bordercolor="#FA6103" ><span class="style4">Hunting Date</span></td>

<td align="center" bordercolor="#FA6103" ><span class="style4">Hunting Location</span></td>

<td align="center" bordercolor="#FA6103"><span class="style4">Weather</span></td>

<td align="center" bordercolor="#FA6103"><span class="style4">Waterfowl Species</span></td>

<td align="center" bordercolor="#FA6103"><span class="style4">Number Killed</span></td>

<td align="center" bordercolor="#FA6103"><span class="style4">Number of Bands</span></td>

<td align="center"> </td>

</tr>

<?php

while($rows=mysql_fetch_array($result)){

?>

<tr>

<td><? echo $rows['huntDate']; ?></td>

<td><? echo $rows['huntLocation']; ?></td>

<td><? echo $rows['huntWeather']; ?></td>

<td><? echo $rows['waterfowlSpecies']; ?></td>

<td><? echo $rows['waterfowlNumberKilled']; ?></td>

<td><? echo $rows['waterfowlBandedNumber']; ?></td>

<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>

</tr>

<?php

}

?>

</table>

</td>

</tr>

</table>

<?php

mysql_close();

?>

 

Link to comment
Share on other sites

GROUP BY won't do it.  You probably want something like this:

 

$sql = "SELECT huntDate, huntLocation, huntWeather, waterfowlSpecies, waterfowlNumberKilled, waterfowlBandedNumber, DATE_FORMAT(huntDate,'%m %d, %Y')
	FROM dbnwaterfowl
	ORDER BY huntDate ASC";

$result = mysql_query($sql);

$date = '';

while($rows = mysql_fetch_array($result)) {
if($rows['huntDate'] != $date) {
	$date = $rows['huntDate'];
	echo $date;
}
// echo other fields
}

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.