0

我设法创建了一个搜索栏来搜索我的论坛,它搜索类别表然后显示结果,但是我想创建一个链接将我重定向到找到的结果,例如我搜索一个名为业务的类别并显示结果,但我希望结果有一个链接,这样当我单击它时,它会将我重定向到该类别,但我收到一个错误

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>'; 
} 
?>
4

3 回答 3

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>"
于 2012-12-28T06:29:00.940 回答
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>"; 
于 2012-12-28T06:30:01.553 回答
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的习惯,它真的会帮助你避免这样的错误

于 2012-12-28T06:31:51.977 回答