Current location: Hot Scripts Forums » Programming Languages » PHP » Advanced Search Problem


Advanced Search Problem

Reply
  #1 (permalink)  
Old 10-12-05, 09:56 AM
php-learner php-learner is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Advanced Search Problem

I am having a simple problem whereby i am filtering data to a browsers requirement to display results from a mysql database. The problem is that when i use the "and" statement and do not enter any data in certain fields i will receive the "no results displayed" unless i can specifically choose criteria from all fields. I am tearing my hear out over something that is meant to be simple but do not know what.

I will paste the sql query code below. What i am trying to do is for example; search for a property in the database where county is like $county and style is like $style and then filters the results accordingly. If i use the 'or' command i know i will retrieve the results from one query or the other. What i am trying to do is be specific but if for example the user places a search criteria in 'county' but not in the style i would like it to filter for criteria matches for county and then set the style to not match as nothing is entered. I have also placed value=0 in the style field so if the field is not chosen it wont need to match any thing. Every time i do this it still results in no results found. I can paste all of my code if it is required but i feel i have a problem in how i am calling these features up.

Can somebody help

Kind Regards

php-learner


My Code


$query = "select * from listings where county like '$county' and style like '$style' order by price DESC limit $offset, $limit";
Reply With Quote
  #2 (permalink)  
Old 10-13-05, 09:51 AM
Satria Satria is offline
Newbie Coder
 
Join Date: Sep 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$withStyle=true;

//$withStyle=false;
$query"SELECT * from listing where country like '$country' ". (($withStyle)?"AND style like '$style'":''). " order by price DESC"
if the middle things make you confuse its just same like:
PHP Code:

$query"SELECT * from listing where country like '$country' ";

if (
$withStyle$query$query ."AND style like '$style'";
$query.=" order by price DESC"
Hope that helping...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Optional search problem SummerL PHP 3 07-22-05 07:21 AM
Search database with multiple AND problem Bonzo PHP 8 07-14-05 02:09 PM
another php search mysql problem sumogray PHP 6 06-28-04 08:03 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM


All times are GMT -5. The time now is 06:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.