gpt4 book ai didi

php - While 循环不显示查询的所有结果

转载 作者:行者123 更新时间:2023-11-29 20:50:19 25 4
gpt4 key购买 nike

This is the modal of a specific customer information i'm trying to make

我在显示模式中的所有结果时遇到问题。我想在模式中显示三行:2016 年 6 月、2016 年 5 月和 2016 年 4 月的计费月份,但仅显示最新的(2016 年 6 月)。这是我的代码的一部分:

if(isset($_GET['id'])) 
{

$page_id = $_GET['id'];

$select_query = "SELECT * FROM billing_info INNER JOIN customer_login ON billing_info.account_no=customer_login.account_no WHERE billing_info.account_no='$page_id' ";

$run_query = mysqli_query($conn,$select_query);

while($row = mysqli_fetch_array($run_query))
{
$id = $row['user_id'];
$cust_fname = $row['cust_fname'];
$cust_mname = $row['cust_mname'];
$cust_lname = $row['cust_lname'];
$branch = $row['branch'];
$account_no = $row['account_no'];
$billing_month = $row['billing_month'];
$pres_reading = $row['pres_reading'];
$prev_reading = $row['prev_reading'];
$payment_status = $row['payment_status'];
$due_date = $row['due_date'];
$int_pres = intval($row["pres_reading"]);
$int_prev = intval($row["prev_reading"]);
$difference = $int_pres-$int_prev;
$payment = $difference*26.678;

$cust_fname = ucfirst($cust_fname);
$cust_mname = ucfirst($cust_mname);
$cust_lname = ucfirst($cust_lname);
$branch = ucfirst($branch);

?>

<div id="openModal" class="modalDialog" style="width:100%;">
<div id="form-sms" style="height: 500px; overflow: scroll;">
<div class="close"><a href="admin-customers.php"> X</a></div>

<form method="get" action="customer_view.php?id=<?php echo $id; ?>" name="id" enctype="multipart/form-data">

<table width="100%" bgcolor="white" align="center">
<style type="text/css">


td.hundred{
width: 80%;
text-align: center;
}
input {
width: 100%;
}
input[type="text"]{
width: 90%;
text-align: left;
}
input[type="submit"]{
width: 100%;
text-align: center;
}
textarea{
width: 90%;
text-align: left;
margin-left: 10%;
}
td {
padding: 10px;
}
.tdhover:hover {

color: #AFEEEE;
}
</style>


<tr >
<td align="center" colspan="10"><h1><?php echo $cust_fname." ".$cust_mname." ".$cust_lname." - ".$account_no." - ".$branch." Details" ?></h1></td>
</tr>

<tr bgcolor="#20B2AA">

<th>Billing Month</th>
<th>Present Reading</th>
<th>Previous Reading</th>
<th>Payment</th>
<th>Status</th>
<th>Due Date</th>
<th>Water Usage (in m<sup>3</sup>)</th>
<th>Edit</th>
</tr>
<tr bgcolor="#AFEEEE">


<td><?php echo $billing_month; ?></td>
<td><?php echo $pres_reading; ?></td>
<td><?php echo $prev_reading; ?></td>
<td><?php echo "Php " . $payment; ?></td>
<td><?php echo $payment_status; ?></td>
<td><?php echo $due_date; ?></td>
<td><?php echo $difference; ?></td>


<td><a href="billing_edit_posts.php?edit=<?php echo $id; ?>">Edit</a></td>
</tr>

<tr style="margin-top: 10px;">
<td bgcolor="#20B2AA" align="center" class="tdhover" colspan="10"><a href="billing_add.php" style="text-decoration:none; color: white; ">Add Billing Information</a></td>
</tr>



</table>
</form>
</style>
</table>
</form>
</div>
</div>


<?php } }?>

最佳答案

您应该仅循环/解析 <tr> 的数据和<td>不适用于所有标签,如 <table><div> table 外面。 Html 将循环 { ... } 内的所有内容符号。然后,你的样式代码应该放在上面(而不是用html/php修复)。您的代码应该是:

        <style type="text/css">
td.hundred{
width: 80%;
text-align: center;
}
input {
width: 100%;
}
input[type="text"]{
width: 90%;
text-align: left;
}
input[type="submit"]{
width: 100%;
text-align: center;
}
textarea{
width: 90%;
text-align: left;
margin-left: 10%;
}
td {
padding: 10px;
}
.tdhover:hover {

color: #AFEEEE;
}
</style>
<?php

if (isset($_GET['id'])) {//open the isset
$page_id = $_GET['id'];
$select_query = "SELECT * FROM billing_info INNER JOIN customer_login ON billing_info.account_no=customer_login.account_no WHERE billing_info.account_no='$page_id' ";

$run_query = mysqli_query($conn, $select_query);
?>


<div id="openModal" class="modalDialog" style="width:100%;">
<div id="form-sms" style="height: 500px; overflow: scroll;">
<div class="close"><a href="admin-customers.php"> X</a></div>

<form method="get" action="customer_view.php?id=<?php echo $id; ?>" name="id" enctype="multipart/form-data">

<table width="100%" bgcolor="white" align="center">
<?php
while ($row = mysqli_fetch_array($run_query)) { //open the while
$id = $row['user_id'];
$cust_fname = $row['cust_fname'];
$cust_mname = $row['cust_mname'];
$cust_lname = $row['cust_lname'];
$branch = $row['branch'];
$account_no = $row['account_no'];
$billing_month = $row['billing_month'];
$pres_reading = $row['pres_reading'];
$prev_reading = $row['prev_reading'];
$payment_status = $row['payment_status'];
$due_date = $row['due_date'];
$int_pres = intval($row["pres_reading"]);
$int_prev = intval($row["prev_reading"]);
$difference = $int_pres - $int_prev;
$payment = $difference * 26.678;

$cust_fname = ucfirst($cust_fname);
$cust_mname = ucfirst($cust_mname);
$cust_lname = ucfirst($cust_lname);
$branch = ucfirst($branch);
?>


<tr >
<td align="center" colspan="10"><h1><?php echo $cust_fname . " " . $cust_mname . " " . $cust_lname . " - " . $account_no . " - " . $branch . " Details" ?></h1></td>
</tr>

<tr bgcolor="#20B2AA">

<th>Billing Month</th>
<th>Present Reading</th>
<th>Previous Reading</th>
<th>Payment</th>
<th>Status</th>
<th>Due Date</th>
<th>Water Usage (in m<sup>3</sup>)</th>
<th>Edit</th>
</tr>
<tr bgcolor="#AFEEEE">


<td><?php echo $billing_month; ?></td>
<td><?php echo $pres_reading; ?></td>
<td><?php echo $prev_reading; ?></td>
<td><?php echo "Php " . $payment; ?></td>
<td><?php echo $payment_status; ?></td>
<td><?php echo $due_date; ?></td>
<td><?php echo $difference; ?></td>


<td><a href="billing_edit_posts.php?edit=<?php echo $id; ?>">Edit</a></td>
</tr>

<tr style="margin-top: 10px;">
<td bgcolor="#20B2AA" align="center" class="tdhover" colspan="10"><a href="billing_add.php" style="text-decoration:none; color: white; ">Add Billing Information</a></td>
</tr>
<?php } //while closing
?>


</table>
</form>
</style>
</table>
</form>
</div>
</div>

希望您会成功;)

关于php - While 循环不显示查询的所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38113271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com