Connecting Tech Pros Worldwide Help | Site Map

PHP script SELECT FROM mysql database WHERE date

  #1  
Old September 30th, 2005, 02:35 AM
pizzy
Guest
 
Posts: 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

  #2  
Old September 30th, 2005, 08:05 AM
Samuel
Guest
 
Posts: n/a

re: PHP script SELECT FROM mysql database WHERE date


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 =)

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is wrong with my PHP script for MySQL updating? Siong.Ong@gmail.com answers 3 April 9th, 2007 02:25 PM
Deleting row in mysql database using php script azmiza answers 2 December 8th, 2006 11:11 AM
How come I can't do this query with php script? 21novembre@gmail.com answers 4 July 17th, 2005 02:47 PM
Help req. Reading data from MySQL db with PHP Dariusz answers 5 July 17th, 2005 01:15 AM