this is the current code of an updates page i have created at:
http://www.no-nothingrock.com/updates/index.php
<?
$db_name = "nonothingrockdb";
$table_name = "nnr_updates";
$connection = @mysql_connect("localhost", "username", "password")
or die("couldn't connect to database.");
$db = mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = "SELECT id, DATE_FORMAT(date, '%W, %M %d, %Y') as date, time, author, updates FROM $table_name WHERE TO_DAYS(NOW()) - TO_DAYS(date) <= 30 ORDER BY id DESC";
$result = @mysql_query($sql,$connection)
or die("couldn't complete query.");
while ($row = @mysql_fetch_array($result)) {
$id = $row ['id'];
$date = $row['date'];
$time = $row['time'];
$author = $row['author'];
$updates = $row['updates'];
$updates_block .= "
<P CLASS=\"date\">$date</P>
<P CLASS=\"main\">$updates</P>
<P CLASS=\"time\">posted by $author | $time</P>
<P> </P>
";
}
?>
what i'm looking to do is to get the date to display once, and every update that has been put in on that date to display.
the code now, displays the date with EACH update like so:
09-15-02
blah blah blah
09-15-02
text text text
09-14-02
blah blah blah
how would i get the first two updates to go under one heading ?
like:
09-15-02
blah blah blah
text text text
09-14-02
blah blha blah
i tried nesting while loops, but that didn't work exactly.
this was the code:
<?
$db_name = "nonothingrockdb";
$table_name = "nnr_updates";
$connection = @mysql_connect("localhost", "username", "password")
or die("couldn't connect to database.");
$db = mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = "SELECT id, DATE_FORMAT(date, '%W, %M %d, %Y') as date FROM $table_name WHERE TO_DAYS(NOW()) - TO_DAYS(date) <= 30 ORDER BY id DESC";
$result = @mysql_query($sql,$connection)
or die("couldn't complete query.");
while ($row = @mysql_fetch_array($result)) {
$id = $row ['id'];
$date = $row['date'];
$updates_block .= "
<P CLASS=\"date\">$date</P>
";
$sql2 = "SELECT * FROM $table_name WHERE date = $date ORDER BY id DESC";
$result2 = @mysql_query($sql2,$connection)
or die("couldn't complete query.");
while ($row2 = @mysql_fetch_array($result2)) {
$time = $row2['time'];
$author = $row2['author'];
$updates = $row2['updates'];
$updates_block .= "
<P CLASS=\"main\">$updates</P>
<P CLASS=\"time\">posted by $author | $time</P>
<P> </P>
";
}
}
?>
any suggestions on how i can correctly script the desired effect ?
thanks.