The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Best "search" practice.
Discuss Best "search" practice. in the PHP Development forum on Dev Shed. Best "search" practice. PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 12th, 2013, 07:42 AM
|
 |
A Change of Season
|
|
|
|
|
Best "search" practice.
Hello I am trying to make a generic search on top right corner of this page. It doesn't work too bad but it is not perfect. I wrote the code below and it woks most of the times but not all the times. For exmple for term "yoga" it works but for "Yoga voucher" it doesn't!
What do you recommend?
Thanks
PHP Code:
$sql = "SELECT *,
atless_deals.id AS DID,
photo_query.file AS file
FROM atless_deals
LEFT OUTER JOIN (SELECT file,
deal_id
FROM atless_deal_photo
ORDER BY main DESC) AS photo_query
ON photo_query.deal_id = atless_deals.id
WHERE atless_deals.status = :status
AND atless_deals.description LIKE :description
GROUP BY atless_deals.id
ORDER BY atless_deals.id DESC";
$args_deals = array('description'=>'%'.$_POST['generic_search'].'%');
|

March 12th, 2013, 08:39 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
PHP Code:
$sql = "SELECT *,
atless_deals.id AS DID,
photo_query.file AS file
FROM atless_deals
LEFT OUTER JOIN (SELECT file,
deal_id
FROM atless_deal_photo
ORDER BY main DESC) AS photo_query
ON photo_query.deal_id = atless_deals.id
WHERE atless_deals.status = :status
AND LOWER(atless_deals.description) LIKE :description
GROUP BY atless_deals.id
ORDER BY atless_deals.id DESC";
$args_deals = array('description'=>'%'.strtolower(mysql_real_escape_string($_POST['generic_search'])).'%');
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

March 12th, 2013, 08:44 AM
|
 |
Lost in code
|
|
|
|
|
Based on the code structure I assume he's using a prepared statement already.
You could look into match_against. It's not perfect, but often better than LIKE. Writing a good search system is pretty hard beyond those two methods.
|

March 12th, 2013, 11:57 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
Quote: Based on the code structure I assume he's using a prepared statement already. | I know, I wrapped everything in UPPER calls.
This requires certain indexes and table types and I was too tired to write all that out, but it's the correct solution.
|

March 12th, 2013, 04:34 PM
|
 |
A Change of Season
|
|
|
|
|
Imagine a Software Developement company with E-oreo, Requinx, Northie, Rudy, catacaustic, ManicDan.
|

March 12th, 2013, 11:01 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
We'd never get anything done, we'd argue constantly about how to make it perfect.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|