[thelist] php/mysql help

Manish Sharma msharma at satyam.net.in
Tue Feb 19 19:15:01 CST 2002


Hello Matt,

This WILL work

Note:
1). The GROUP BY clause in the first SQL query. This gets the distinct
values.
2). The second SQL query (in the while loop) picks a "distinct" value and
then loops through the entries using "for"

<?php
include ("db.php");

$sql = "select * from entries group by entry_date order by entry_date desc";

$result = mysql_query($sql);

while ($data = mysql_fetch_array($result))
   {
   $sql2 = "select * from entries where entry_date =
\"$data[entry_date]\";";
   $result2 = mysql_query($sql2);
   $date = strtotime ($row["entry_date"]);
   $date = date("F j, Y", $date);
   print "$date<BR>\n";
   $total_entries = mysql_num_rows($result2);
   for ($i = 0; $i < $total_entries; $i++)
      {
      $row = mysql_fetch_array($result2);
      print "&nbsp;&nbsp;&nbsp;&nbsp;$row[entry_body]<BR>\n";
      }
   }
?>

Regards,
Manish Sharma
http://www.simplygraphix.com - Extreme Design
http://www.fontmagic.com - Largest True Type fonts directory on the Internet
http://www.webdevelopersnotes.com - Tutorials, tips, tricks, web page design
and much more




More information about the thelist mailing list