用PHP显示SQL数据

用PHP显示SQL数据,php,html,sql,Php,Html,Sql,嗨,堆栈溢出的用户们 我面临的问题是,我的SQL数据无法正确显示,我不确定如何解决这个问题。我只看到打印部分,没有适当的数据 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/htm

嗨,堆栈溢出的用户们

我面临的问题是,我的SQL数据无法正确显示,我不确定如何解决这个问题。我只看到打印部分,没有适当的数据

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <link rel="stylesheet" href="css/default.css" type="text/css" />
 <link rel="stylesheet" href="css/timetable.css" type="text/css" />
<title>Timetable Information</title>
</head>
<body>


<div id="header"></div>


<ul id="NavigationList">
<li><a href="Index.php">Index</a></li>
<li><a href="ModuleInfo.php">Module Info</a></li>
<li><a href="ModuleSearch.php">Module Search</a></li>
<li><a href="Timetable.php">Timetable Search</a></li>

</ul>
<p>
<p>Please select a school from the drop-down list.</p>

   <?php
require('json.php');
error_reporting(E_ALL);
$connection = mysql_connect('localhost', 'root','') or
    die("Could not connect: " . mysql_error());
mysql_select_db("timetable") or die("No such database");
$sql = sprintf("
  SELECT id,day,start,module
    FROM event JOIN teaches ON (event.id=teaches.event)
   WHERE staff='%s'", mysql_real_escape_string($_REQUEST['staff']));
$result = mysql_query($sql)
  or die(mysql_error());
while ($row = mysql_fetch_array($result)){
    print "<div>$row[id] $row[module] $row[day] $row[start]</div>\n";
}
?>
</p>
<div id="Footer">
            <p id="FooterText">Copyright &copy; 2012 .<br     />All     rights reserved.</p>    
            </div>
</body>
</html>

时间表信息
请从下拉列表中选择一所学校

使用:

打印“{$row['id']}{$row['module']}{$row['day']}{$row['start']}\n”;
而不是:

print "<div>$row[id] $row[module] $row[day] $row[start]</div>\n";
打印“$row[id]$row[module]$row[day]$row[start]\n”;
试试这个

while ($row = mysql_fetch_array($result)){
echo "<div>".$row['id'];
echo $row['module'];
echo $row['day'];
echo $row['start'];
echo "</div>";
}
while($row=mysql\u fetch\u array($result)){
回显“.$row['id'”;
echo$row['module'];
echo$行['day'];
echo$row['start'];
回声“;
}
而不是:
打印“$row[id]$row[module]$row[day]$row[start]\n”

试试这样的东西

print "<div>".$row[id]. $row[module]. $row[day]. $row[start]."</div>\n";
print'.$row[id]$行[模块]$行[日]$行[开始]。“\n”;
while($row=mysql\u fetch\u assoc($result)){
$symbol=$row['symbol'];
$date=$row['date'];
$avgprice=$row['avg_price'];
$var4=$row['field4']
.“
”; 回声“ “$symbol。” “$date。” “$avgprice。” “$4。” ";
mysql\u connect('localhost','root','')
-nice)字段名周围是否应该有引号?请删除错误报告并发布您将得到的错误。这样我们就可以更准确地调试它。@RohitKumarChoudhary我没有收到任何错误,我得到的显示是{$row['id']}{$row['module]}{$row['day']}{$row['start']}\n;}?>尝试只打印SQL查询并运行它,查看它是否显示任何数据我已经更改了它,但它只显示行,而不显示表中的数据。是否确定
mysql_num_rows($result)
返回的值大于0?显示-“$row['id'];echo$row['module'];echo$row['day'];echo$row['start'];echo”“;}?>试试这个$sql=“选择id,day,start,模块从事件JOIN teachs ON(event.id=teachs.event),其中staff='%s',mysql\u real\u escape\u string($_REQUEST['staff']);$result=mysql\u query($sql)
print "<div>".$row[id]. $row[module]. $row[day]. $row[start]."</div>\n";
while ($row = mysql_fetch_assoc($result)) { 
    $symbol= $row['Symbol'];
    $date= $row['Date']; 
    $avgprice= $row['avg_price']; 
    $var4 = $row['field4']
    ."<br>";


    echo "<tr>
        <td >".$symbol."</td>
        <td >".$date."</td>
        <td >".$avgprice."</td>
        <td >".$var4."</td>

    </tr>";