Jump to content


Photo

If & Elseif Statements


  • Please log in to reply
3 replies to this topic

#1 Duncan Disorderly

Duncan Disorderly
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationBirmingham UK

Posted 28 June 2006 - 07:12 PM

I would be grateful if someone could tell me the correct syntax to use with the code below.
Additionally, is there some method I can use to process an "any / all records" option from a series of combo box/dropdowns

kind regards
DD

If ($l_Type==1 AND $L_Area==1 AND $L_value==1) {
$result = mysql_query("Select * FROM listings")or die(mysql_error());

} elseif ($l_Type>1 AND $L_Area==1 AND $L_Value==1) {
$result = mysql_query("Select * FROM listings WHERE listings.`Type`='$L_Type'")or die(mysql_error());

} elseif($l_Type==1 AND $L_Area>=1 AND $L_Value==1) {
$result = mysql_query("Select * FROM listings WHERE listings.`Area`='$L_Area'")or die(mysql_error());

} elseif($l_Type==1AND $L_Area==1 AND $L_Value>1) {
$result = mysql_query("Select * FROM listings WHERE listings`.`Value`='$L_Val'")or die(mysql_error());

} elseif($l_Type>1 AND $L_Area>1 AND $L_Value==1) {
$result = mysql_query("Select * FROM listings WHERE listings.`Type`='$L_Type' AND `listings`.`Area`='$L_Area'")or die(mysql_error());

} elseif($l_Type>1 AND $L_Area==1 AND $L_Value>1) {
$result = mysql_query("Select * FROM listings WHERE listings.`Type`='$L_Type' AND `listings`.`Value`='$L_Val'")or die(mysql_error());

} elseif($l_Type==1 AND $L_Area>1 AND $L_Value>1) {
$result = mysql_query("Select * FROM listings WHERE listings`.`Value`='$L_Val' AND `listings`.`Area`='$L_Area'")or die(mysql_error());

} else {
$result = mysql_query("Select * FROM listings WHERE listings.`Type`='$L_Type' AND `listings`.`Value`='$L_Val' AND `listings`.`Area`='$L_Area'")or die(mysql_error());
}



#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 28 June 2006 - 07:14 PM

try putting the "I" in lowercase "if"

is something else not working?

#3 Duncan Disorderly

Duncan Disorderly
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationBirmingham UK

Posted 28 June 2006 - 07:48 PM

[!--quoteo(post=388954:date=Jun 28 2006, 02:14 PM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Jun 28 2006, 02:14 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
try putting the "I" in lowercase "if"

is something else not working?
[/quote]

cmgmyr,
Thanks, lowercase "I" indeed helped,

.....THIS NEEDS TO BE READ INCONJUNCTION WITH THE CODE IN MY ORIGINAL POST......
However (Hope you can follow this!....)
I have three dropdowns, type, area and value, a user can select a value from "each box (or they default to "Any"- value =1) to search on.

Problem: Selecting the "any record" (ie: value==1) option from any of the three dropdowns does not select "All" records of that option.

Ie: if all three dropdowns were set to "any" it would mean..
Display all records of "any value" and "in any area" and "of any type" or variations
currently as long as the dropdowns are NOT set to "any" the search works.

I want to be able to select:
All records (any,any,any)
Records of Any Value and of Type=X and in Area=X
Records of Any Type and of Value =X and in Area=X
Records in Any Area and of Type=X and of Value=X
Records in Area=X and of Type=X and of Value=X - this works currently
And variations of the above..


if anyone can understand my babble above and offer some sound advice (other than give up..lol) I would be most grateful

DD

#4 Duncan Disorderly

Duncan Disorderly
  • Members
  • PipPip
  • Member
  • 16 posts
  • LocationBirmingham UK

Posted 28 June 2006 - 10:39 PM

Resolved

Tip for all Noobies like me.... check your capitalisation... variables are case sensitive ....

I had "If" when it should be "if" (thx cmgmyr) and "$l_Type" when it should be "$L_Type"

Dowh... hrs wasted...

DD
46 y.o idiot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users