[thelist] php/mysql help

Anthony Baratta Anthony at Baratta.com
Tue Feb 19 18:43:01 CST 2002


At 04:27 PM 2/19/2002, Sarah Heffron wrote:
>Sorry for not being clear, anyhow, the data is coming from mysql.
>
>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.

Sarah...

There are a bazillion ways to tackle this. Here's one:
(my PHP is very rusty, take this with a grain of salt.)

$sql = "select entry_body, entry_date  ";
$sql .= "from entries order by entry_date desc";
$result = mysql_query($sql);
$total_entries = mysql_num_rows($result);

$MonthDay = "";
for ($i = 0; $i < $total_entries; $i++) {
         $row = mysql_fetch_array($result);
         $date = strtotime ($row["entry_date"]);

        if ($MonthDay ne date("F j", $date)) {
            $MonthDay = date("F j", $date);
            $date = date("F j, Y", $date);
        } else {
            $date = date("g:i a", $date);
         }
        echo "$date<br>";
         echo $row["entry_body"] . "<br>";
         echo "<br><br>";
}

----
Anthony Baratta
President
Keyboard Jockeys

"Conformity is the refuge of the unimaginative."




More information about the thelist mailing list