使用PHP将数据从MySQL视图呈现为HTML


Present data from a MySQL view into HTML using PHP

我试图简单地使用PHP在MySQL中显示视图,但我不断获得和错误。关于T_STRING错误可能是什么有什么建议吗?谢谢。

解析错误:语法错误,未预料的T_STRING/home/theaudit/public_html/_sandbox/index.php第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);
?>
$query = SELECT * FROM a_aif_remaining;

必须是:

$query = "SELECT * FROM a_aif_remaining";

找一个更好的编辑器,你可以马上修复和改进你的代码:

<?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);
?>