Re: PHP script SELECT FROM mysql database WHERE date
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: PHP script SELECT FROM mysql database WHERE date

From: Samuel <lets.monroe@gmail.com>
Date: Fri Sep 30 2005 - 08:52:05 CEST

In your first example you'd have to sort the data with php, and in the
second you'd have to query the database once for each date you want to
show. I'd recommend this instead;

SELECT * FROM pictures ORDER BY date

You will be able to get all the data you need in only one query. The
script would basically look like this.

<?php
//Assuming you already opened and selected the db...
$query = "SELECT * FROM pictures ORDER BY date";
$result = mysql_query ($query);

while (($number_of_items < 30) && ($row = mysql_fetch_array($result)))
{
if ($last_date != $row['date'])
    print_break_between_dates_or_whatever();

print_the_data_or_whatever($row);

$last_date = $row['date'];
$number_of_items++;
}

?>

Hope I helped and all =)
Received on Tue Oct 18 02:29:50 2005