Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Searchings also in extra contents pages  (Read 1425 times)

etatus

  • Newbie
  • *
  • Karma: 2
  • Posts: 8
Searchings also in extra contents pages
« on: November 28, 2007, 02:46:34 am »

Hi, i made some changes in search() function in order to enable searchings also in extra contents pages (linked to a normal page). Commented lines are related with the modifications...

(I think I would be interesting that searchings will consider comments too)

Code: [Select]
//SEARCH ENGINE
function search() {
$search_query = clean(cleanXSS($_POST['search_query']));
echo '<h2>'.l(search_results).'</h2>';
if (strlen($search_query) < 4 || $search_query == l('search_keywords')) {echo '<p>'.l(charerror).'</p>';}
else {
$keywords = explode(' ', $search_query);
$keyCount = count($keywords);
//$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
$query = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND";
if ($keyCount > 1) {
for ($i = 0; $i < $keyCount - 1; $i++) {$query = $query." (title LIKE '%$keywords[$i]%' || text LIKE '%$keywords[$i]%') &&";}
$j = $keyCount - 1;
$query = $query." (title LIKE '%$keywords[$j]%' || text LIKE '%$keywords[$j]%')";
}
else {$query = $query." (title LIKE '%$keywords[0]%' || text LIKE '%$keywords[0]%')";}
$query = $query." ORDER BY id DESC";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if (!$numrows) {echo '<p>'.l('noresults').' <strong>'.stripslashes($search_query).'</strong>.</p>';}
else {
echo '<p><strong>'.$numrows.'</strong> '.l('resultsfound').' <strong>'.stripslashes($search_query).'</strong>.</p>';
while ($r = mysql_fetch_array($result)) {
//These 2 lines are new:
  if ($r['category']==-1) $item_seftitle=retrieve('seftitle','articles','id',substr(''.$r['position'],2));
else $item_seftitle=$r['seftitle'];
$date = date(s('date_format'), strtotime($r['date']));
//echo '<p><a href="'.db('website').find_cat_sef($r['category']).'/'.$r['seftitle'].'/">'.$r['title'].'</a> - '.$date.'</p>';
echo '<p><a href="'.db('website').find_cat_sef($r['category']).'/'.$item_seftitle.'/">'.$r['title'].'</a> - '.$date.'</p>';
        }
}
}
echo '<p><br /><a href="'.db('website').'">'.l('backhome').'</a></p>';
$searched = true;
}

Edited: Corrected a bug in the code. Now it should work fine  ;)
« Last Edit: November 28, 2007, 04:41:20 pm by etatus »
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Searchings also in extra contents pages
« Reply #1 on: November 28, 2007, 01:48:13 pm »

Hi, and very welcome etatus... Nice first post you've got here... Haven't really tried it out as time do not permit me just now, but I'm sure this will come in handy as sites have grew to use more and more of those extras... Thanks, mate. Hope you'll have a wonderful stay here with us.
Logged
"It's only dead fish that goes with the flow... "
Updated

piXelatedEmpire

  • MIA
  • ULTIMATE member
  • ******
  • Karma: 37
  • Posts: 1401
  • currently MIA
Re: Searchings also in extra contents pages
« Reply #2 on: November 28, 2007, 10:45:34 pm »

I've moved this into the Programming section for the time being, which will allow some of our members to perhaps try out your code. 

Welcome to sNews etatus, we very much welcome your contributions!
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future