【发布时间】:2014-11-24 03:28:20
【问题描述】:
我整天都在尝试让这个愚蠢的页面正常工作,但我无法弄清楚。我正在尝试从表中获取信息以显示在 php 文件中的表中。
if (!mysql_connect($servername, $username, $password))
die("Connection failed: ");
if (!mysql_select_db($dbname))
die("Can't select database");
$result = mysql_query("SELECT problem_id, machine_id, description FROM tbl_problem");
if (!$result)
{
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table class='table table-hover'><tr><th>Problem ID</th><th>Machine Number</th><th>Problem Description</th><th> </th></tr>";
while($row = mysql_fetch_row($result))
{
echo "<tr><td>" . $row['problem_id']. "</td><td>" . $row['machine_id']. "</td><td>" . $row['description']. "</td><td><button type='button' class='btn btn-danger'>Resolved?</button></td></tr>";
}
echo "</table>";
我已经使用了几个网站来尝试让它工作,但似乎没有任何工作。如果语法真的不正常,那是因为我在模仿我所看到的一切类似于我正在尝试做的事情之后对其进行建模。
它应该做的是,如果表格“tbl_problem”中有数据,在网站上显示一个表格,显示问题 ID、机器 ID 和描述以及右侧的按钮,允许您从“tbl_problem”中删除该行(该按钮现在作为占位符存在,我还没有实际删除它的代码,但如果有人想用它指出我正确的方向,我会非常感谢!)。
当我运行它时,我没有得到任何表格,而是看到以下内容:
问题 ID 机器编号问题描述 "; while($row = mysql_fetch_row($result)) { echo "" . $row['problem_id']. "" . $row['machine_id']. "" . $row[ '描述']. ""; } echo "[已解决?按钮在这里正确显示]"; /else { echo "没有问题! :)"; }/ ?>
【问题讨论】: