PDA

View Full Version : Developing a "Phonebook" With Microsoft Access



Aragoth
11-15-2006, 04:58 PM
Please Note: First time user of anything "database".

I have a school assignment in which I must create a pseudo phonebook with 30 entries, and each entry having to be described by their first and last names, their adresses, their phone numbers, and a variety of other seemingly random details. I have completed the table (along with its various entries) and now I am posed with a problem. I am supposed to "Design a query where you print off individuals who are born in the same month." How would I go about creating something like that? Thanks in advance...

boxxertrumps
11-15-2006, 11:41 PM
if its for school asking for a code here is cheating.

you would have to have a month column in your database table, then select it.
IE
mysql_query("SELECT * FROM phonebook WHERE month='febuary'");
then echo each result.

http://www.w3schools.com/php/php_mysql_intro.asp

read that section over. it helps.


ps. pointing you in the right direction isnt cheating

Aragoth
11-16-2006, 01:22 AM
I don't feel its really cheating since my teacher's don't even have a clue. They just assign it to me and expect me to get it done. Kind of a ripoff...

mwinter
11-17-2006, 02:56 AM
you would have to have a month column in your database table, then select it.

Not at all. Use the built-in SQL EXTRACT function (any decent database should implement it)

  EXTRACT(field FROM source)

using a field value of 'month':

  SELECT * FROM phonebook WHERE EXTRACT(MONTH FROM dob) = 2

Permitted types for source will vary, but date/time types should always be accepted. The documentation for your DBMS will contain more information.

Mike

Aragoth
11-17-2006, 05:20 PM
Do you know how one would access the source in Access? Probably not...
Anyway, the dates are divided into dd/mm/yyyy format. Will that be a problem with the query?

mwinter
11-17-2006, 09:51 PM
Do you know how one would access the source in Access?

Open the Query in design view, then open the context menu and select "SQL View" from the top of the menu. You can also use the View menu, and the View toolbar button.



Anyway, the dates are divided into dd/mm/yyyy format.

As long as the column is a Date/Time type, the format doesn't matter.

An amendment to my previous post: in Access, use the DatePart (http://office.microsoft.com/en-us/access/HA012288121033.aspx) function. The first argument is the portion of the value, and the second is the date value. For example,

  SELECT * FROM phonebook WHERE DatePart('m', dob) = 2

is the Access equivalent to second SQL statement in my previous post, which would return everyone that was born in February.

Mike

Aragoth
11-21-2006, 04:39 PM
I have never used any type of database before, so please bear with me. I can understand what you are saying (the query would extract the data from the table entitled Phonebook). Must I match the fields exactly in the example you provided? I attempted to add the script you gave directly into the SQL view, but the result was that the query saved, and allowed me to enter data, but did not access the months of February when 2 was entered. Is there something wrong with the way I placed the code, or do I have to edit it to meet my specific needs?