By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,154 Members | 1,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,154 IT Pros & Developers. It's quick & easy.

PHP script SELECT FROM mysql database WHERE date

P: n/a
Problem:

I am trying to develope my personal site to select from my mysql
database and organize data on the page so that it will display all the
submissions for that day, then break and display the next day, then
break and display the third day, etc...
Question:

Should I query the whole database into an array and then sort with php?
Example: SELECT * FROM pictures

Or should I (and I would prefer) query an array with the dates I need?
Example: SELECT * FROM pictures WHERE date = $array[$i]

Can you provide an example of how the php script would look? I am
looking for some types of special functions I might be missing from php
or mysql.

Any help will be greatly appreciated.
Thanks,

pizzy

Sep 30 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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 =)

Sep 30 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.