Jump to content

Recommended Posts

It's a search script (adding links etc. with the hand)!

 

<?PHP 

  //### Maximum results per page
  $maxPerPage = 20;

  if(isSet($_GET['query']) && strlen($_GET['query']) >= 1 ) {
    include('connection.php');

    //### Get and filter the search term entered
    $searchTerm = mysql_real_escape_string($_GET['query']);
    $searchTerm = explode(' ',$searchTerm);
    $termCount  = 0;
    foreach($searchTerm AS $term) { $termCount++;
      if($termCount == 1) {
        $query .= " WHERE keywords LIKE '%$term%' ";
      } else {
        $query .= " OR keywords LIKE '%$term%' ";
      }

    }



    //### Count total results
    $totalResults = mysql_num_rows(mysql_query("SELECT * FROM search_links ".$query.""));

    if(!$totalResults) {echo 'We could not find any results to match your search query.'; exit; }

    //### Get inital starting point for records
    $start = isSet($_GET['s']) ? (int)$_GET['s'] : 0 ;
    if($start > $totalResults-1) { $start = $totalResults-1; }

    //### Configure the next a prev links to conform with result count
    $next = ($start+$maxPerPage)>=$totalResults ? $totalResults-1 : $start+$maxPerPage ;
    $prev = ($start-$maxPerPage)<0 ? 0 : $start-$maxPerPage ;

    //### Now we do the search for the results
    $doSearch   = mysql_query("SELECT * FROM search_links ".$query." LIMIT $start,$maxPerPage");
echo '<title>avata.rs - Search: ',implode(' ',$searchTerm),'</title>';

    if(mysql_num_rows($doSearch)) {
      echo 'Results for "<span class="result">',implode(' ',$searchTerm),'</span>".<br><br>';

      while($result = mysql_fetch_assoc($doSearch)) {
        echo '<div class="results">';
        echo '<span class="resulth"><a href="',$result['link'],'">',$result['title'],'</a></span> - <span class="resultd">',$result['description'],'</span><br>';
        echo '';
	echo '<span class="resultl">',$result['link'],'';
        echo '</div>';
      }

      echo '<a href="search.php?query=',implode(' ',$searchTerm),'&s=',$prev,'"><<Previous</a>  ';
      echo '<a href="search.php?query=',implode(' ',$searchTerm),'&s=',$next,'">Next>></a>';

    } else {
      //### No results so we tell them and offer another search
      echo 'We could not find any results to match your search query.'; exit;
    }

  } else {

    header('Location: index.html'); exit;

  }
  
  
?>

Link to comment
https://forums.phpfreaks.com/topic/230816-problem-with/#findComment-1188259
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.