PHP SQL搜索系统


PHP SQL search systems

我正在尝试建立一个搜索系统。我用过mySQL系统,但我没有什么经验,我不太懂。

  • 我想通过数据库中的字段post_title进行搜索然后得到URL,日期
  • 我也希望能够通过标签搜索。为此,我们需要连接表wp_term_relationships,这将为我们提供一个带有post id的列和一个带有标签id的列。然后,我们可以从中找出应用哪些标签。

My try failed with FATAL ERROR

<?php 
$proto = $_GET['proto'];
$terms = $_GET['f'];
if($proto == 'inline'){
    $searchpattern = mysql_real_escape_string(strtoupper($terms));
    $list = mysql_query("SELECT    id, 
           post_title,  post_date
 FROM      wp_posts 
 WHERE     post_title LIKE '%$searchpattern%'
)
    ORDER BY post_date;");
while ($row = mysql_fetch_array($list)) {
    $title = $row['post_title'];
    $date =  $row['post_date'];
    $url =  $row['guid'];
    $date = date($date, 'd M Y');
    $return .= '<li>
                <a href="#sidebar3" onClick="slide(this); return false" title="" rel="'.$id.'" style="line-height:16px;">'.$firstname.' '.$lastname.'<br /><span style="font-size:10px; color:#555;">'.$email.'</span></a>
            </li>

            <div class="title"><b>SEARCH RESULTS</b></div>
    <a href="'.$url.'"><img src=""/>'. $title .' - <span>'. $date .'</span></a>';
}
}
?>
 $list = mysql_query("SELECT id,  post_title,  post_date 
FROM wp_posts 
WHERE post_title LIKE '%$searchpattern%') ORDER BY post_date;");

在"ORDER"操作符之前有意外的")"。

在ORDER BY前有一个左括号。也许这就是导致问题的原因