我有一个名为payment_status
的数据库,其中包含以下列:
-id
-user_id
-firstname
-payment_name
-payment_id
-payment_amount
我正在尝试构建这个,所以如果payment_id
= = 1,那么该表将显示该表列中具有该id的所有用户。
如果用户的payment_id
为2或3,则同样适用,但2为'部分付费',3为'付费'。
我的数据库中有payment_id
为1的用户,但没有显示任何用户。我只收到了其他陈述。
是否有人能够看到我做错了什么不让任何用户显示?
<?php
//Payment Section
$con = mysqli_connect("localhost", "root", "", "db");
$run = mysqli_query($con,"SELECT * FROM payment_status ORDER BY id DESC");
$numrows = mysqli_num_rows($run);
$payment_id = $row['payment_id'];
if($payment_id == 3 AND $numrows > 0) {
while($row = mysqli_fetch_assoc($run)){
$paid_id = $row['user_id'];
$paid_name = $row['firstname'];
}
} else {
echo "No Payments made";
}
if($payment_id == 2 AND $numrows > 0) {
while($row = mysqli_fetch_assoc($run)){
$partially_paid_id = $row['user_id'];
$partially_paid_name = $row['firstname'];
$partially_paid_amount = $row['payment_amount'];
}
} else {
echo "No Partial Payments made";
}
if($payment_id == 1 AND $numrows > 0) {
while($row = mysqli_fetch_assoc($run)){
$owes_id = $row['user_id'];
$owes_name = $row['firstname'];
}
} else {
echo "No one owes";
}
?>
表
<table class="paymentTable" id="dragTable">
<tr>
<th class="thPayment">Paid</th>
<th class="thPayment">Partially Paid</th>
<th class="thPayment">Owes</th>
</tr>
<tr>
<td class="tdPayment" id="paid">
<div>
<?php
if ($paid_name == true) {
echo $paid_name;
} else {
echo "No one has paid";
}
?>
</div>
</td>
<td class="tdPayment" id="partially_paid">
<div>
<?php
if ($partially_paid__name == true) {
echo $partially_paid__name . " - " . $partially_paid_amount;
} else {
echo "No one has made a partial payment";
}
?>
</div>
</td>
<td class="tdPayment" id="owes">
<div>
<?php
if ($owes_name == true) {
echo $owes_name;
} else {
echo "Everyone has paid something";
}
?>
</div>
</td>
</tr>
</table>
答案 0 :(得分:1)
您需要执行以下操作: -
<?php
//Payment Section
$con = mysqli_connect("localhost", "root", "", "db");
$run = mysqli_query($con,"SELECT * FROM payment_status ORDER BY id DESC");
$numrows = mysqli_num_rows($run);
if( $numrows > 0) {
while($row = mysqli_fetch_assoc($run)){
$payment_id = $row['payment_id'];
if($payment_id == 3){
$paid_id = $row['user_id'];
$paid_name = $row['firstname'];
}else {
echo "No Payments made";
}
if($payment_id == 2){
$partially_paid_id = $row['user_id'];
$partially_paid_name = $row['firstname'];
$partially_paid_amount = $row['payment_amount'];
}else {
echo "No Partial Payments made";
}
if($payment_id == 1){
$owes_id = $row['user_id'];
$owes_name = $row['firstname'];
}else {
echo "No one owes";
}
}
}
?>