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

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 2.40 KB  |  hits: 8  |  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. Ordering PHP results with a generated number
  2. $refType = $_GET["ref"];
  3. $setLimit = $_GET["list"];
  4.  
  5. //CATCH & SECURE THE QUERY
  6. $q = mysql_real_escape_string($_GET["q"]);
  7.  
  8. //SET LISTING VALUE IF CHOSEN, DEFAULT 10
  9. if(!$setLimit || $setLimit == "0"){
  10. $setLimit = "10";
  11. } else {
  12. $setLimit = $_GET["list"];
  13. }
  14.  
  15. //GET NUMBER OF WORDS IN QUERY & RETURN ERROR IF MORE THAN 12
  16.  
  17. $searchTermCount = str_word_count($q);
  18. if($searchTermCount > 12){
  19. $searchLine = "";
  20. $searchList = "Your search contained too many words! Please go back and try again, use less than 12 words to find what you are looking for.";
  21. } else if($q == "" || !$q || $q == " "){
  22. $searchLine = "";
  23. $searchList = "You did not submit a search term! Please go back and enter your city into the search bar!";
  24. } else {
  25.  
  26. $searchLine = "Your search for " . $q . " found the following results";
  27.  
  28. //PUT NEW ALGORITHM HERE
  29.  
  30. $findDetails = mysql_query("SELECT * FROM [TABLENAME] WHERE upper(city) like '%$q%' AND verified='1' OR upper(county) like '%$q' AND verified='1' OR upper(title) like '%$q%' AND verified='1' OR upper(intro) like '%$q%' AND verified='1' OR upper(content) like '%$q%' AND verified='1' ORDER BY datePosted DESC LIMIT $setLimit");
  31. while($row = mysql_fetch_array($findDetails)){
  32.     $adId = $row["id"];
  33.     $adTitle = $row["title"];
  34.     $adIntro = $row["intro"];
  35.     $adCity = $row["city"];
  36.     $adCounty = $row["county"];
  37.     $adVerified = $row["verified"];
  38.     $cutIntro = substr($adIntro, 0, 140);
  39.  
  40.     $numberOfResults = mysql_num_rows($findDetails);
  41.  
  42.     $findReviews = mysql_query("SELECT * FROM [TABLENAME2] WHERE adventureID='$adId'");
  43.     $findReviews = mysql_num_rows($findReviews);
  44.  
  45.     $titleScore = "";
  46.     $introScore = "";
  47.     $contentScore = "";
  48.  
  49.     //CUT SEARCH TERM
  50.     $qBreak = explode(" ", $q);
  51.     foreach($qBreak as $qWord){
  52.     $titleScore = $titleScore+substr_count($adTitle, $qWord);
  53.     $introScore = $introScore+substr_count($adIntro, $qWord);
  54.     $contentScore = $contentScore+substr_count($adContent, $qWord);
  55.     }
  56.  
  57.     $totalScore = $titleScore+$introScore+$contentScore;
  58.  
  59.     $searchList .='
  60.     <div style="width: 100%;" class="result' . $totalScore . '">
  61.     ' . $adTitle . '<br />' . $adIntro . '<br /><br />' . $adContent . '
  62.     <br /><br /><br />
  63.     Total Score: ' . $totalScore . '<br />
  64.     Title Score: ' . $titleScore . '<br />
  65.     Intro Score: ' . $introScore . '<br />
  66.     Content Score: ' . $contentScore . '<br /><br />
  67.     </div>
  68.     ';
  69.  
  70. }
  71.  
  72. }