Loading a variable with content from a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jza
Forum Newbie
Posts: 17
Joined: Sat Sep 23, 2006 10:10 am

Loading a variable with content from a database

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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';
Jza
Forum Newbie
Posts: 17
Joined: Sat Sep 23, 2006 10:10 am

Post by Jza »

Thanks for the reply.
Post Reply