- Ordering PHP results with a generated number
- $refType = $_GET["ref"];
- $setLimit = $_GET["list"];
- //CATCH & SECURE THE QUERY
- $q = mysql_real_escape_string($_GET["q"]);
- //SET LISTING VALUE IF CHOSEN, DEFAULT 10
- if(!$setLimit || $setLimit == "0"){
- $setLimit = "10";
- } else {
- $setLimit = $_GET["list"];
- }
- //GET NUMBER OF WORDS IN QUERY & RETURN ERROR IF MORE THAN 12
- $searchTermCount = str_word_count($q);
- if($searchTermCount > 12){
- $searchLine = "";
- $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.";
- } else if($q == "" || !$q || $q == " "){
- $searchLine = "";
- $searchList = "You did not submit a search term! Please go back and enter your city into the search bar!";
- } else {
- $searchLine = "Your search for " . $q . " found the following results";
- //PUT NEW ALGORITHM HERE
- $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");
- while($row = mysql_fetch_array($findDetails)){
- $adId = $row["id"];
- $adTitle = $row["title"];
- $adIntro = $row["intro"];
- $adCity = $row["city"];
- $adCounty = $row["county"];
- $adVerified = $row["verified"];
- $cutIntro = substr($adIntro, 0, 140);
- $numberOfResults = mysql_num_rows($findDetails);
- $findReviews = mysql_query("SELECT * FROM [TABLENAME2] WHERE adventureID='$adId'");
- $findReviews = mysql_num_rows($findReviews);
- $titleScore = "";
- $introScore = "";
- $contentScore = "";
- //CUT SEARCH TERM
- $qBreak = explode(" ", $q);
- foreach($qBreak as $qWord){
- $titleScore = $titleScore+substr_count($adTitle, $qWord);
- $introScore = $introScore+substr_count($adIntro, $qWord);
- $contentScore = $contentScore+substr_count($adContent, $qWord);
- }
- $totalScore = $titleScore+$introScore+$contentScore;
- $searchList .='
- <div style="width: 100%;" class="result' . $totalScore . '">
- ' . $adTitle . '<br />' . $adIntro . '<br /><br />' . $adContent . '
- <br /><br /><br />
- Total Score: ' . $totalScore . '<br />
- Title Score: ' . $titleScore . '<br />
- Intro Score: ' . $introScore . '<br />
- Content Score: ' . $contentScore . '<br /><br />
- </div>
- ';
- }
- }