0

嗨 Stack Overflow 的用户,

我遇到了一个问题,我的 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>
4

4 回答 4

1
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>";
于 2014-03-07T18:00:56.650 回答
1

利用:

print "<div>{$row['id']} {$row['module']} {$row['day']} {$row['start']}</div>\n";

代替:

print "<div>$row[id] $row[module] $row[day] $row[start]</div>\n";
于 2012-04-23T11:29:11.297 回答
0

尝试这样的事情

print "<div>".$row[id]. $row[module]. $row[day]. $row[start]."</div>\n";
于 2012-04-23T12:00:16.453 回答
0

尝试这个

while ($row = mysql_fetch_array($result)){
echo "<div>".$row['id'];
echo $row['module'];
echo $row['day'];
echo $row['start'];
echo "</div>";
}

而不是: print "$row[id] $row[module] $row[day] $row[start]\n";

于 2012-04-23T11:43:24.603 回答