0

This is a keyword search script for one table only (pages). i need this search on 2 tables (pages and services) with one result set at the end to echo to the page. Can anyone help me? I have been trying to find a solution for 2 days - it would take too long to describe what I have already tried :) Thank you!

$todo=$_POST['todo'];
if(isset($todo) and $todo=="search"){
$search_text=$_POST['search_text'];
$type=$_POST['type'];

$bad_string = $search_text;
$bad_chars=array(',', '!', '.', 'ï','»','¿','â','¢','®');
$search_text=str_replace($bad_chars,'',$bad_string);

$search_text=ltrim($search_text);
$search_text=rtrim($search_text);

db_connect();

if($type<>"any"){
$query="select * FROM pages WHERE page_text='$search_text' ";
}else{
$kt=split(" ",$search_text);
while(list($key,$val)=each($kt)){
if($val<>" " and strlen($val) > 0){$q .= " page_text like '%$val%' or ";}

}

$q=substr($q,0,(strlen($q)-3));

$query="select * FROM pages where $q";

} 

$result=mysql_query($query);
echo mysql_error();

$num_results = mysql_num_rows($result);


   echo "<table cellspacing = 0 cellpadding = 10>";



   while($row=mysql_fetch_array($result)){

     $page_text = $row['page_text'];
     $qid = $row['qid'];
     $page_name = $row['page_name'];


     echo "<tr><td>";
     echo '* <u><a href="';
     echo $page_name;
     echo '.php">';
     echo substr($row['page_text'],0,100);
     echo '... *read more...</a></u><br><br>';
     echo "</td></tr>";
  }   
     echo "</table>";

  }

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by jtdbidirect
0

First, let's see how it looks with proper code tags.

$todo=$_POST['todo'];
if(isset($todo) and $todo=="search"){
$search_text=$_POST['search_text'];
$type=$_POST['type'];

$bad_string = $search_text;
$bad_chars=array(',', '!', '.', 'ï','»','¿','â','¢','®');
$search_text=str_replace($bad_chars,'',$bad_string);

$search_text=ltrim($search_text);
$search_text=rtrim($search_text);

db_connect();

if($type<>"any"){
$query="select * FROM pages WHERE page_text='$search_text' ";
}else{
$kt=split(" ",$search_text);
while(list($key,$val)=each($kt)){
if($val<>" " and strlen($val) > 0){$q .= " page_text like '%$val%' or ";}

}

$q=substr($q,0,(strlen($q)-3));

$query="select * FROM pages where $q";

} 

$result=mysql_query($query);
echo mysql_error();

$num_results = mysql_num_rows($result);


echo "<table cellspacing = 0 cellpadding = 10>";



while($row=mysql_fetch_array($result)){

$page_text = $row['page_text'];
$qid = $row['qid'];
$page_name = $row['page_name'];


echo "<tr><td>";
echo '* <u><a href="';
echo $page_name;
echo '.php">';
echo substr($row['page_text'],0,100);
echo '... *read more...</a></u><br><br>';
echo "</td></tr>";
} 
echo "</table>";

}
0

Thank you, Chrishea!
I have been working on this for days. Any help would be greatly appreciated.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.