Page 1 of 1

Loading a variable with content from a database

Posted: Sat Oct 21, 2006 8:57 am
by Jza
Hello,

I need to write a PHP script capable of doing the following:
- Grab information from a database and load it into an array (I think).
- All information that is going to be grabbed are going to be numbers.
- I then need to use in_array to check if the array containing the values from the database match a number in the script.

I'm not exactly sure about how I should go about loading information from a database into an array, the database structure will have one field named 'date', this will contain the number I want to extract. It will have another field named month. I need it to grab all the dates that correspond to any given month (say, january). Doing that alone isn't a big problem, I can make it output, but I can't make it load into a variable.

Any help is appreciated.
Jeff

Posted: Sat Oct 21, 2006 9:05 am
by feyd
Unless you have a strange storage format, there's no reason to pull all the data into php to search when the database can perform the action faster and with less memory requirements.

The basic idea is:

Code: Select all

SELECT field1, field2 FROM table1 WHERE field3 = 'some value';

Posted: Sat Oct 21, 2006 9:07 am
by Jza
Thanks for the reply.