Posted By

mattneary on 01/22/11


Tagged

form mysql php search tags categories Ternary


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

julianrhyswilliams
fomigo


MySQL Search/Category Filter


 / Published in: PHP
 

URL: http://mneary.info/home/search.php

I thought this was pretty elegant code and wanted to share it with anyone who found it useful.

  1. $query = $search ?
  2. ( !$cat ?
  3. "SELECT * FROM games WHERE name LIKE '%".$search."%'" :
  4. "SELECT * FROM games WHERE category='".$cat."' AND name LIKE '%".$search."%'"
  5. ):
  6. ( $cat ?
  7. "SELECT * FROM games WHERE category='".$cat."'" :
  8. "SELECT * FROM games WHERE name='N/A'"
  9. );
  10. basic_connect($query);

Report this snippet  

You need to login to post a comment.