我設法創建一個搜索欄來搜索我的論壇,它搜索類別表然後顯示結果,但是我想創建一個鏈接將我重定向到找到的結果,例如我搜索所謂的一類業務,它顯示的結果,但我希望結果能有這樣的鏈接,當我點擊它,它重定向我該類別 但我得到一個錯誤在php中重定向一個頁面
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\mysite\captcha2\tut.php on line 43
我上線43碼
<td>'.$category_title.="<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a>"'</td>
</tr>'
這是我的搜索ba R代碼裏面
if(isset($_POST['search'])){ //form submitted, clicked Submit Search
$query = strip_tags(mysql_real_escape_string($_POST['query'])); //try to prevent sql injections
if(!$query){ //not enterered a query
echo 'You must enter a search query!';
}else{
$table = 'categories'; //the table you want to search
$row = 'category_title'; //the row in which you want to search
$sql = mysql_query("SELECT * FROM `".$table."` WHERE `".$row."` LIKE '%".$query."%'"); //search query
if($sql){ //no errors
if(mysql_num_rows($sql) == 0){ //No results found.
echo 'No results were found for <strong>'.$query.'</strong>';
}else{ //one or more results have been found
echo 'We have found <strong>'.mysql_num_rows($sql).'</strong> for <strong>'.$query.'</strong>.<br><br>
<table>
<tbody>
<tr>
<td><strong>category_title</strong></td>
</tr>';
while($r = mysql_fetch_array($sql)){ //get data of every user where their category_title is like the $query string
$category_title = $r["category_title"];
//lets put the part they searched in bold.
$category_title = str_ireplace($query, '<strong>'.$query.'</strong>', $category_title);
//lets put the part they searched in bold.
echo '<tr>
<td>'.$category_title.="<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a>"'</td>
</tr>';
}
echo '</tbody></table>';
}
}else{
echo 'Sorry, an MySQL error occurred:<br><br>'.mysql_error(); //an error occurred, so echo it
}
}
}else{ //not clicked Submit Search, so echo the form
echo '<h3>Search</h3>
<br><br>
<form method="post">
<label for="q"></label> <input type="text" size="100" name="query" id="q" value="m0nsta.">
<input type="submit" name="search" value="Search">
</form>';
}
?>
獲取編輯至少最基本最小的剛剛夠,TO-使用語法高亮。 –