943,172 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 30
  • PHP RSS
Aug 31st, 2010
0

Need hdlp with this script! I have tried everything but what will work.

Expand Post »
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!




[code=php]
$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>";

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jtdbidirect is offline Offline
2 posts
since Aug 2010
Sep 1st, 2010
0
Re: Need hdlp with this script! I have tried everything but what will work.
First, let's see how it looks with proper code tags.

php Syntax (Toggle Plain Text)
  1. $todo=$_POST['todo'];
  2. if(isset($todo) and $todo=="search"){
  3. $search_text=$_POST['search_text'];
  4. $type=$_POST['type'];
  5.  
  6. $bad_string = $search_text;
  7. $bad_chars=array(',', '!', '.', 'ï','»','¿','â','¢','®');
  8. $search_text=str_replace($bad_chars,'',$bad_string);
  9.  
  10. $search_text=ltrim($search_text);
  11. $search_text=rtrim($search_text);
  12.  
  13. db_connect();
  14.  
  15. if($type<>"any"){
  16. $query="select * FROM pages WHERE page_text='$search_text' ";
  17. }else{
  18. $kt=split(" ",$search_text);
  19. while(list($key,$val)=each($kt)){
  20. if($val<>" " and strlen($val) > 0){$q .= " page_text like '%$val%' or ";}
  21.  
  22. }
  23.  
  24. $q=substr($q,0,(strlen($q)-3));
  25.  
  26. $query="select * FROM pages where $q";
  27.  
  28. }
  29.  
  30. $result=mysql_query($query);
  31. echo mysql_error();
  32.  
  33. $num_results = mysql_num_rows($result);
  34.  
  35.  
  36. echo "<table cellspacing = 0 cellpadding = 10>";
  37.  
  38.  
  39.  
  40. while($row=mysql_fetch_array($result)){
  41.  
  42. $page_text = $row['page_text'];
  43. $qid = $row['qid'];
  44. $page_name = $row['page_name'];
  45.  
  46.  
  47. echo "<tr><td>";
  48. echo '* <u><a href="';
  49. echo $page_name;
  50. echo '.php">';
  51. echo substr($row['page_text'],0,100);
  52. echo '... *read more...</a></u><br><br>';
  53. echo "</td></tr>";
  54. }
  55. echo "</table>";
  56.  
  57. }
Reputation Points: 210
Solved Threads: 228
Nearly a Posting Virtuoso
chrishea is offline Offline
1,389 posts
since Sep 2008
Sep 1st, 2010
0
Re: Need hdlp with this script! I have tried everything but what will work.
Thank you, Chrishea!
I have been working on this for days. Any help would be greatly appreciated.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jtdbidirect is offline Offline
2 posts
since Aug 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: logout user if already logged in
Next Thread in PHP Forum Timeline: Errors sent to DIV?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC