[thelist] php/mysql help
Sarah Heffron
sarah at meatlike.com
Tue Feb 19 18:27:00 CST 2002
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
-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Matthew Mullenweg
Sent: Tuesday, February 19, 2002 4:09 PM
To: thelist at lists.evolt.org
Subject: RE: [thelist] php/mysql help
Where is the data coming from? (database, text file...)
Here's an example of parsing data from a mysql database. Like so:
// this assumes a connection to the database using mysql_pconnect
$sql = mysql_query("SELECT * FROM people") or die(mysql_error());
while ($row = mysql_fetch_array($sql)) {
$first = $row['first']; //assign variables to the fields in the
database which have been broken into an array
$nick = $row['nickname'];
$middle = $row['middle'];
$last = $row['last'];
// now conc. the formatted data
$people .= "<p><strong>$first $middle $last</strong><br
/>\n$first's nickname is '$nick'";
}
Then later on in the page you can just echo it out wherever you want it:
<h1>People and their nicknames</h1>
<?php echo $people; ?>
Hope that's at least a little relevant to your question. If not just
fire back some specifics :)
-Matt
> From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]
> On Behalf Of Sarah Heffron
> Sent: Tuesday, February 19, 2002 5:36 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] php/mysql help
>
> I have some data that I would like to display in this fashion:
>
> Feburary 19, 2002
> 9:14am
> blahblahblah
<snip>
--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !
More information about the thelist
mailing list