[SOLVED] Having multiple conditions in search query

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
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

[SOLVED] Having multiple conditions in search query

Post by Milan »

can i have a multiple AND conditions in a query for example if i have

Code: Select all

$sql = "SELECT time, dates,events, dayofmonth(dates) as days FROM pickageek.calendar WHERE MONTH(dates)='$month' AND YEAR(dates)='$year'";
can this also work as

Code: Select all

$sql = "SELECT time, dates,events, dayofmonth(dates) as days FROM pickageek.calendar WHERE MONTH(dates)='$month' AND YEAR(dates)='$year' AND user='USERNAME'";
Last edited by Milan on Thu Jun 01, 2006 5:40 pm, edited 1 time in total.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Re: having multiple conditions in search query

Post by PrObLeM »

yes
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

fast and sharp!

thanks!
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

edit: i started writing this before those other responses
What?

Code: Select all

$sql = sprintf("
SELECT time, dates, events, dayofmonth(dates) as days
FROM pickageek.calendar
WHERE MONTH(dates) = '%s' AND YEAR(dates) = '%s' AND user = '%s'
", mysql_real_escape_string($month), 
mysql_real_escape_string($year), 
mysql_real_escape_string($username));
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Daedalus- wrote:edit: i started writing this before those other responses
What?

Code: Select all

$sql = sprintf("
SELECT time, dates, events, dayofmonth(dates) as days
FROM pickageek.calendar
WHERE MONTH(dates) = '%s' AND YEAR(dates) = '%s' AND user = '%s'
", mysql_real_escape_string($month), 
mysql_real_escape_string($year), 
mysql_real_escape_string($username));
I think you're in the wrong tread little buddy. viewtopic.php?t=49424
Milan
Forum Commoner
Posts: 97
Joined: Wed May 17, 2006 6:08 pm

Post by Milan »

THANKS!

you people are REALY helpfull. Cant wait to finish the website and show you how much can be done with your help.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I think that I was trying to help him out and I also think that I don't need sarcastic comments from you.

That's just my opinion though.

Just in case you really think that I posted in the wrong thread, I take that back.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Daedalus- wrote: Just in case you really think that I posted in the wrong thread, I take that back.
yea I'm sorry too, the code you posted looked like it was from the other tread so I thought it was a misspost
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Well, that's my method when I need to include a WHERE clause.

I do it everywhere.
Post Reply