Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.63 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP code to correctly handle an HTML query
  2. SELECT * FROM $tableName WHERE category RLIKE ('option-choice') and
  3. genre RLIKE ('option-choice') and Sub_genre RLIKE ('option-choice')
  4. and lyrical_theme RLIKE ('option-choice') and lead RLIKE
  5. ('option-choice') and tempo RLIKE ('option-choice'); "
  6.        
  7. <select id="category" name="category"><option value="" class="header">Category</option>
  8.        
  9. $query1= "SELECT * FROM $tableName
  10. WHERE category= '$category' AND genre='$genre' AND sub_genre= '$sub_genre'
  11. LIMIT $start, $limit";
  12.        
  13. $query1 = "SELECT * FROM $tableName WHERE [some condition thats always required]";
  14. if (!empty ($category))
  15.     $query1 .= "AND category = '$category' ";
  16. if (!empty ($genre))
  17.     $query1 .= "AND genre= '$genre' ";
  18. [etc...]
  19. $query1 .= "LIMIT $start, $limit;"
  20.        
  21. SELECT * FROM $tableName
  22. WHERE category RLIKE 'Indie'
  23. and genre RLIKE 'Blues'
  24. and Sub_genre RLIKE ''
  25. and lyrical_theme RLIKE ''
  26. and lead RLIKE ''
  27. and tempo RLIKE '';
  28.        
  29. <?php
  30. $arrConditions = Array();
  31. if (isset($_POST['category']) && !empty($_POST['category'])) {
  32.     $arrConditions[] = 'category RLIKE "' . $_POST['category'] . '"';
  33. }
  34. if (isset($_POST['genre']) && !empty($_POST['genre'])) {
  35.     $arrConditions[] = 'genre RLIKE "' . $_POST['genre'] . '"';
  36. }
  37. if (isset($_POST['sub_genre']) && !empty($_POST['sub_genre'])) {
  38.     $arrConditions[] = 'Sub_genre RLIKE "' . $_POST['sub_genre'] . '"';
  39. }
  40. /* ADD SIMILAR IF STATEMENTS FOR ALL OTHER FORM FIELDS */
  41.  
  42. $qryWhere = '';
  43. if (!empty($arrConditions)) { // assuming that there is at least one condition
  44.     $qryWhere = ' WHERE ' . implode(' AND ', $arrConditions);
  45. }
  46. $query = 'SELECT * FROM ' . $tableName . ' ' . $qryWhere;
  47. ?>