我在将回声放入div标签层时遇到了问题。我尝试了多次尝试将div标签放入div标签层,以便轻松移动结果" name"轻松地在页面上,所以当它显示在浏览器上时,它可以是页面的左侧,右侧或中心。在此之前,我试图在HTML中回应它,但不能正常工作。下面是我的页面脚本 - useracc-test.php
<?php
//useracc-test.php
session_start();
// require 'lib/password.php';
require 'connect-test.php';
$userName=$_POST['username'];
//$sql = "SELECT name, username FROM users WHERE username = '" . $_POST['username'] . "'";
//$result = $conn->query($sql);
$query = sprintf("select name, username, telno FROM users WHERE username='%s'", mysql_real_escape_string($userName));
$result = $conn->query($query); ?>
<?php while($row=$result->fetch_assoc()): ?>
<div id="satu"><?= $row['name'] ?></div>
<div id="dua"><?= $row['username'] ?></div>
<div id="tiga"><?= $row['telno'] ?></div>
<?php endwhile; ?>
<html>
<head>
<style type="text/css">
#apDiv2 {
position: absolute;
left: 51px;
top: 238px;
width: 237px;
height: 93px;
z-index: 1;
}
#apDiv1 {
position: absolute;
left: 50px;
top: 344px;
width: 234px;
height: 104px;
z-index: 2;
}
</style>
</head>
<body>
<div id="apDiv2"><span class="error"><?php echo $userName; ?></span></div>
<div id="apDiv1"><span class="error"><?php echo $row['telno'] ?></span></div>
</body>
</html>
答案 0 :(得分:1)
如果您希望结果显示在正文中,那么您需要回显/输出结果。只需将块复制到HTML正文,如下所示:
<body>
<div id="apDiv2"><span class="error"><?php echo $userName; ?></span></div>
<div id="apDiv1"><span class="error"><?php echo $row['telno'] ?></span></div>
<?php while($row=$result->fetch_assoc()): ?>
<div id="satu"><?= $row['name'] ?></div>
<div id="dua"><?= $row['username'] ?></div>
<div id="tiga"><?= $row['telno'] ?></div>
<?php endwhile; ?>
</body>
</html>
答案 1 :(得分:0)
你可以这样做:
<?php while($row=$result->fetch_assoc()): ?>
<div id="satu"><?= $row['name'] ?></div>
<div id="dua"><?= $row['username'] ?></div>
<div id="tiga"><?= $row['telno'] ?></div>
<?php endwhile; ?>