Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql and PHP and/or help

Status
Not open for further replies.

darryncooke

Technical User
May 6, 2009
308
US
Hi,

So I have some results I am trying to get into a query and I can get the AND statement working fine.

The problem I am having is such.

I am searching industries and cities. However lets say someone wants to search an industry but no city I get no results. I tried making the default value of each "*" but that didnt work.

Is there a default select ALL?

I have right now

Code:
$ind_industry_search = "*";
if (isset($_GET['industry'])) {
  $ind_industry_search = $_GET['industry'];
}
$cty_industry_search = "*";
if (isset($_GET['city'])) {
  $cty_industry_search = $_GET['city'];
}

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
That probably tells you that there is no city called ''. But you probably won't have a city called '*' either.

So you have to issue a different query is one of the fields was empty.

By the way, if one is given, both are. So if I do not give a city but I do give an industry, $_GET['city'] will be set to an empty string.


+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
well i am setting my url string as such

directory.php?industry=some industry&city=some city

so you are saying that I can change the "*" to "" and it will work? because it didnt.

Darryn Cooke
| The New Orange County Graphic designer and Marketing and Advertising Consultant
| Marketing and Advertising blog
 
you cannot have spaces in a query string. you must encode them.
 
Code:
$sql = "select * from table where 1=1 ";
foreach(array('industry','city') as $type){
 if(isset($_GET[$type] && $_GET[$type]!='ALL')){
   $sql .= " AND $type = '" . mysql_real_escape_string(trim($_GET[$type])) . "'";
 }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top