[thelist] php/mysql help

Matthew Mullenweg matt at swcdesign.com
Tue Feb 19 18:40:00 CST 2002


Ohhhh okay. This might not be the best/most efficient way to do it, but
it'll work:

$sql = "SELECT DISTINCT entry_date FROM entries ORDER BY entry_date
DESC";
$result = mysql_query($sql);
// I'm going to skip the total entries thing, they both do the same
thing basically

while ($row = mysql_fetch_array($sql)) {
	$entry_date = $row['entry_date'];
	$display .= "<h1>$entry_date</h1>\n";

	// now lets select all the entries for that date
	$events = mysql_query("SELECT * FROM entries WHERE entry_date =
$entry_date");
	while ($row = mysql_fetch_array($events)) {
		$event_body = $row['event_body'];
		$display .= "<p>$event_body</p>";
		}
	}

Try dropping that in and let me know if it works.

> -----Original Message-----
> From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]
> On Behalf Of Sarah Heffron
> Sent: Tuesday, February 19, 2002 6:27 PM
> To: thelist at lists.evolt.org
> Subject: RE: [thelist] php/mysql help
>
> Sorry for not being clear, anyhow, the data is coming from mysql.
>
> This is what I have:
>
> $sql = "select * from entries order by entry_date desc";
> $result = mysql_query($sql);
> $total_entries = mysql_num_rows($result);
>
> for ($i = 0; $i < $total_entries; $i++) {
> 	$row = mysql_fetch_array($result);
> 	$date = strtotime ($row["entry_date"]);
> 	$date = date("F j, Y", $date);
> 	echo "$date<br>";
> 	echo $row["entry_body"] . "<br>";
> 	echo "<br><br>";
> }
>
>
> I want to print out a date and then all the entries for that date
> underneath
> it (this is to be a "food journal") and then onto the next date, etc..
> Right
> now what I have will print out date and entry for every entry no
matter
> what. ColdFusion had a nice group attribute that made this quite easy,
I'm
> not sure if theres an equivalent for PHP.
>
> So what will print out is something like this:
>
> February 19, 2002
> 1.
> 2.
> 3.
>
> February 18, 2002
> 1.
> 2.
>
> rather than:
>
>
> February 19, 2002
> 1.
> February 19, 2002
> 2.
> February 19, 2002
> 3.
>
> I hope that that is more easily understood.
>
> Thanks,
> Sarah




More information about the thelist mailing list