2014-09-20 57 views
-1

我要導航到一個PHP頁面 這被動態地分配一個截面的截面..導航到一個PHP頁面的一個動態分配的部分

 mysql_connect("localhost", "root", "") or die(mysql_error()); 
    mysql_select_db("somedb") or die(mysql_error()); 
    $data = mysql_query("SELECT * FROM events") 
     or die(mysql_error()); 
    while($info = mysql_fetch_array($data)) 
    { 
    Print "<hr>"; 
    Print "<section id=".$info['title'] .">"; 
    Print "<h1>".$info['title'] . "</h1>"; 
    echo nl2br ($info['desc'],true) ; 
    Print "</section>";} 
    ?> 

從這個PHP代碼

<?php 
    mysql_connect("localhost", "root", "") or die(mysql_error()); 
    mysql_select_db("somedb") or die(mysql_error()); 
    $data = mysql_query("SELECT title FROM events") 
    or die(mysql_error()); 
    while($info = mysql_fetch_array($data)) 
    { 
    echo "<a href="events.php#.$info['title'].">" 
    Print " ".$info['title'] .""; 
    } 
    ?> 

我得到這樣

Parse error: syntax error, unexpected 'events' (T_STRING) in C:\xampp\htdocs\IETE\index - Copy.php on line 91 

錯誤請幫助:)

+0

什麼行91? index.php – 2014-09-20 07:24:47

回答

0

錯誤消息和StackOverflow語法突出顯示器清楚地顯示了問題。引號包含一個字符串,但是在字符串中有一個引號需要轉義,或者可以使用單引號將字符串包圍起來,這比讀取雙引號更容易閱讀。

此行是問題:

echo "<a href="events.php#.$info['title'].">" 

你可以從語法高亮,報價前看到「事件」中斷你出的字符串。散列之後的所有內容都被解釋爲註釋。

將其更改爲使用單引號:

echo '<a href="events.php#' . $info['title'] . '">'; 

或替代,在字符串中逃脫報價:

echo "<a href=\"events.php#" . $info['title'] . "\">"; 

順便說一句,如果您使用的是純文本編輯器我強烈建議切換到IDE,並使用所用語言的更高級功能。

+0

謝謝你這麼多:) – Yashesh 2014-09-20 07:57:21

相關問題