我设法创建了一个搜索我的论坛的搜索栏,它搜索类别表然后显示结果,但是我想创建一个链接,将我重定向到找到的结果,例如我搜索一个名为business的类别它显示结果,但我希望结果有一个链接,当我点击它时,它会将我重定向到该类别 但我收到了一个错误
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>'
这是我的搜索条形码
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>';
}
?>
答案 0 :(得分:3)
摆脱=符号和额外的引用
<td>'.$category_title.="<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a>"'</td>
</tr>'
应该是
<td>'.$category_title."<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a></td>
</tr>"
答案 1 :(得分:1)
."</font></a>"'</td>
</tr>';
这应该以双引号结束,而不是像
那样单一echo '<tr> <td>'.$category_title."<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a></td></tr>";
答案 2 :(得分:0)
使用强>
<td>'.$category_title."=<a href='view_category.php?cid=".$id."' class='cat_links'>".$title." - <font size='-1'>".$description."</font></a></td>
</tr>'";
利用eclipse IDE作为习惯,它将真正帮助您避免此类错误