我目前有一个从我的数据库中提取用户票的功能。它正确地提取数据但由于某种原因而不是在两个单独的行上回显票号,它将它们放在表的第一行。任何人都可以帮我弄清楚为什么会这样吗?
这是功能:
function findUserTickets() {
include_once("dbh.php");
$id = $_SESSION['id'];
$sql = "SELECT * FROM tickets WHERE uid=$id";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
echo "Ticket #".$row['tid'];
}
mysqli_close($conn);
}
这是HTML代码:
<ul>
<?php
include("includes/functions.inc.php");
include_once("includes/dbh.php");
$userID = $_SESSION['id'];
$strSQL = "SELECT * FROM tickets WHERE uid='$userID'";
$rs = mysqli_query($conn, $strSQL);
while ($row = mysqli_fetch_array($rs)) {
?>
<li>
<div class="hk_sug_domian_name">
<p>
<?php echo findUserTickets(); ?>
</p>
</div>
<div class="hk_domain_price">
<span class="active_price"><?php echo checkTicketStatus(); ?> </span>
<div class="hk_promot_btn"><a class="hk_btn" href="progress.php">View</a></div>
</div>
</li>
<?php
}
mysqli_close($conn);
?>
</ul>
答案 0 :(得分:1)
您可以使用$ row
,而不是直接调用函数从
改变<div class="hk_sug_domian_name">
<p>
<?php echo findUserTickets(); ?>
</p>
</div>
到
<div class="hk_sug_domian_name">
<p>
<?php echo "Ticket #".$row['tid']; ?>
</p>
</div>