Solved

Will someone help with this MySQL Query?

Posted on 2008-10-21
2
204 Views
Last Modified: 2013-11-19
I can't figure out why this query still shows results where PaidID=''.

The url calling this would be: ...?page=listing/results&State=FL

OR

$SEARCH="FL"; << Session

if (isset($_SESSION['search'])){

$SEARCH=$_SESSION['search'];
 

if (!ereg('[^0-9]', $SEARCH)){$searchResult = mysql_query("SELECT * FROM members WHERE ZipCodes LIKE '%$SEARCH%' AND PaidID!='' ");}
 

elseif (!ereg('[^A-Z]', $SEARCH) && (strlen($SEARCH) == 2)){

$searchResult = mysql_query("SELECT * FROM members WHERE PaidID!='' AND LicState LIKE '%$SEARCH%' OR LicState2 LIKE '%$SEARCH%' OR LicState3 LIKE '%$SEARCH%' OR LicState4 LIKE '%$SEARCH%' ");

}
 

elseif (isset($_GET['State'])){
 

$searchResult = mysql_query("SELECT * FROM members WHERE
 

(LicState='$State' AND Counties LIKE '%$SEARCH%') OR 

(LicState2='$State' AND Counties2 LIKE '%$SEARCH%') OR 

(LicState3='$State' AND Counties3 LIKE '%$SEARCH%') OR 

(LicState4='$State' AND Counties4 LIKE '%$SEARCH%')
 

AND PaidID!=''

 ");
 

}
 

elseif ($SEARCH=="EXAMPLE"){

$searchResult = mysql_query("SELECT * FROM members WHERE PaidID!='' ORDER BY RAND() LIMIT 5");

}
 

else{

$searchResult = mysql_query("SELECT * FROM members WHERE Counties LIKE '%$SEARCH%' OR Counties2 LIKE '%$SEARCH%' OR Counties3 LIKE '%$SEARCH%' OR Counties4 LIKE '%$SEARCH%'  PaidID!='' ");

}
 

if (!$searchResult){die(mysql_error());}

	

$num_rows= mysql_num_rows($searchResult);
 

}
 

if ($num_rows==0){include ("pages/listing/results_none.php");}

else{include ("pages/listing/results_found.php");}

Open in new window

0
Comment
Question by:phpretard
2 Comments
 
LVL 1

Accepted Solution

by:
yeruhn earned 500 total points
Comment Utility
Use brackets in your query. Like:

SELECT * FROM members WHERE PaidID!='' AND (LicState LIKE '%$SEARCH%' OR LicState2 LIKE '%$SEARCH%' OR LicState3 LIKE '%$SEARCH%' OR LicState4 LIKE '%$SEARCH%' )

Dependent on what you want to select...
0
 

Author Closing Comment

by:phpretard
Comment Utility
Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now