473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PHP script SELECT FROM mysql database WHERE date

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
1 3273
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: coding | last post by:
The purpose of the script below is to load the same news item into two different MySQL tables (thus displaying the same news item on two web pages). The problem I am having is this: The script...
4
by: 21novembre | last post by:
Hi all, I'm working on my first php+mysql program. I have a mysqld running and there's a DB named "example" with a table "tbl". Here it is: -------------- mysql> use example; Reading table...
21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
0
by: Mark Griffin | last post by:
Hi... I am trying to convert a simple FAQ script to access mysql db rather than the Access db it was designed for. The originators of the script offer no support at all. I have managed to set...
14
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
2
by: azmiza | last post by:
Hi everybody, I need your help. I want to view my sql database and its work very well which is display in my web browser but once I want to press button yes, its not working, I check the...
3
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
2
by: starfi3ld | last post by:
I got a few errors with this script Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/starfi3ld/domains/starfi3ld.com/public_html/newreleases.php on line...
82
by: happyse27 | last post by:
Hi All, I modified the user registration script, but not sure how to make it check for each variable in terms of preventing junk registration and invalid characters? Two codes below : a)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.