2012-12-28 80 views
0

我設法創建一個搜索欄來搜索我的論壇,它搜索類別表然後顯示結果,但是我想創建一個鏈接將我重定向到找到的結果,例如我搜索所謂的一類業務,它顯示的結果,但我希望結果能有這樣的鏈接,當我點擊它,它重定向我該類別 但我得到一個錯誤在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>'; 
} 
?> 
+2

獲取編輯至少最基本最小的剛剛夠,TO-使用語法高亮。 –

回答

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>" 
+0

+1銳利的眼睛.. –

+1

嗨,布萊恩我認爲結束你的建議的一部分有一個小的打字錯誤?最後一個字符串以雙引號開始,以單引號結尾 –

+0

感謝您指出@HankyPanky – Bryan

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>"; 
+0

注意:未定義變量:C:\ xampp \ htdocs \ mysite \論壇中的id第二部分\ line 75上的\ index.php 注意:未定義變量:C:\ xampp \ htdocs \ mysite \ forum中的標題第二部分\ line 75上的\ index.php 注意:未定義變量:C:\ xampp \ htdocs \ mysite \ forum第二部分中的描述\ index .php on line 75即時通訊如果我使用你的代碼 – theuserkaps

+0

這意味着你在那裏使用的那些變量沒有被定義過,但這也意味着語法錯誤被解決了 –

+0

就我看到的你的代碼而言,那些3您未在此聲明中使用的變量未定義。 $ title,$ id,$ description –

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作爲一種習慣,它會真正幫助你避免這樣的錯誤

+0

或Netbeans或其他任何東西,但是一個IDE。無論如何,你的回答並不好(刪除'=')。 –