2012-12-24 49 views
-1

我試圖簡單地在PHP中使用PHP顯示視圖,但是我一直在收到和出現錯誤。任何有關T_STRING錯誤的建議?謝謝。使用PHP將數據從MySQL視圖轉換爲HTML

Parse error: syntax error, unexpected T_STRING in /home/theaudit/public_html/_sandbox/index.php on line 14

<?php 

// connection parameters 
$db_host="a"; 
$username="b"; 
$password="c"; 
$db_name="d"; 

// connection variables 
$db_con=mysql_connect($db_host,$username,$password); 
$connection_string=mysql_select_db($db_name); 

// page variables 
$query = SELECT * FROM a_aif_remaining; 
$result = mysql_query($query); 

// connection to mysql and db 
mysql_connect($db_con) or die("Unable to connect to MySQL"); 
mysql_select_db($db_name) or die("Unable to select database"); 

// successful result 

echo "<table border=1> 
     <tr> 
     <th>aif</th> 
     <th>fee_source</th> 
     <th>company_screename</th> 
     <th>filing_date</th> 
     <th>document_subtype</th> 
    </tr>"; 

while($row = mysql_fetch_array($result)) 
    { 
    echo "<tr>"; 
    echo "<td>" . $row['aif_id'] . "</td>"; 
    echo "<td>" . $row['fee_source_id'] . "</td>"; 
    echo "<td>" . $row['company_name_per_sedar'] . "</td>"; 
    echo "<td>" . $row['document_filing_date'] . "</td>"; 
    echo "<td>" . $row['document_subtype'] . "</td>"; 
    echo "</tr>"; 
    } 
echo "</table>"; 

mysql_close($con); 
?> 
+0

忘了'」 '$ query = SELECT * FROM a_aif_remaining;'中的引號,改爲'$ query =「SELECT * FROM a_aif_remaining」;' – dbf

+2

[參考 - 這個錯誤在PHP中意味着什麼?](http://stackoverflow.com/q/12769982/367456) – hakre

+0

爲什麼要調用mysql_connect()兩次?第二次錯誤,我會加 –

回答

1

讓自己更好的編輯器,你可以修復和改善在任何時候你的代碼:

<?php 

// connection parameters 
$db_host = "a"; 
$username = "b"; 
$password = "c"; 
$db_name = "d"; 

// connection variables + connection to mysql and db 
$db_con = mysql_connect($db_host, $username, $password); 
$result = mysql_select_db($db_name, $db_con); 

// page variables 
$query = 'SELECT * FROM a_aif_remaining'; 
$result = mysql_query($query, $db_con); 

// successful result 
echo '<table border=1> 
    <tr> 
    <th>aif</th> 
    <th>fee_source</th> 
    <th>company_screename</th> 
    <th>filing_date</th> 
    <th>document_subtype</th> 
</tr>'; 

while ($row = mysql_fetch_array($result)) { 
    echo "<tr>"; 
    echo "<td>" . $row['aif_id'] . "</td>"; 
    echo "<td>" . $row['fee_source_id'] . "</td>"; 
    echo "<td>" . $row['company_name_per_sedar'] . "</td>"; 
    echo "<td>" . $row['document_filing_date'] . "</td>"; 
    echo "<td>" . $row['document_subtype'] . "</td>"; 
    echo "</tr>"; 
} 
echo "</table>"; 

mysql_close($db_con); 
?> 
+0

失去第二組調用mysql_connect()'&&'mysql_select_db()'和OP將在業務:) –

+0

是的,另一個變量被錯誤地設置。 – hakre

+0

@Michael。感謝您的建議,但我不明白。你是什​​麼意思失去第二組電話?謝謝。 – Ben

2
$query = SELECT * FROM a_aif_remaining; 

需求是:

$query = "SELECT * FROM a_aif_remaining"; 
+0

這是正確的。我現在有另一個問題,雖然...「mysql_query()期望參數1是字符串」 – Ben

+1

檢查hakre的答案。他刪除了一些額外的代碼,它可能會幫助你。你也可能想看看mysqli或PDO。 mysql_ *已被棄用。 – Class