[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

select statemnt with mulitple and condination in php

i just tried to use this sql statement to do a selection :

$sql ="SELECT meetingDate FROM  meetingTable WHERE meetingMonth='$monthVal' AND signed='N' AND taken='N'" ;

i used two and here. is there a syntax error?

thanks so much for your reply!
0
lilyyan
Asked:
lilyyan
  • 5
  • 4
  • 2
3 Solutions
 
carchitectCommented:
$sql ="SELECT meetingDate FROM  meetingTable WHERE meetingMonth='{$monthVal}' AND signed='N' AND taken='N' " ;
0
 
lilyyanAuthor Commented:
>>{$monthVal}

may you explain why use { } ?  thanks for your reply
0
 
Rok-KraljCommented:
$sql ="SELECT meetingDate FROM  meetingTable WHERE meetingMonth='".$monthVal."' AND signed='N' AND taken='N'" ;

{} is for php to threat this as variable. You have faster solution above.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
carchitectCommented:
0
 
lilyyanAuthor Commented:
based on carchitect:'s reply, i don't have to use a { } in the above select statement.
0
 
lilyyanAuthor Commented:
based on carchitect:'s reply, i don't have to use a { } in the above select statement ?
0
 
Rok-KraljCommented:
Look at my solution above, and no, you don't have to use {}... It is just slower method to do something.
0
 
lilyyanAuthor Commented:
anyway last question:

why you use two dot (.) beside the variable?
0
 
Rok-KraljCommented:
dot sign is for merging more strings into one...

example:

$string='one'.'and'.'two';



Have you tried if my solution works?

If you have anything more to ask, just do it :D
0
 
lilyyanAuthor Commented:
well, i would say:

$sql =" SELECT meetingDate FROM  meetingTable WHERE meetingMonth='$monthVal' AND signed='N' AND taken='N'" ;   // is correct ?


don't have to use: WHERE meetingMonth=='".$monthVal."'  //  don't have to use the dot sign and double
                                                                                             //quation mark ?
0
 
Rok-KraljCommented:
Yes, it is also correct what you wrote above... :D

This is because php founds $ sign in string and interprets $monthVal as value, because next character (') isn't valid for name.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now