gpt4 book ai didi

php - 试图创造交易历史

转载 作者:行者123 更新时间:2023-11-28 23:15:12 26 4
gpt4 key购买 nike

大家好,我正在尝试制作交易历史记录,当然是从数据库中获取类(class)的详细信息。

当用户订阅有效时,详细信息显示完美,但当订阅到期时不显示任何内容,只显示 1 行。

我想在历史记录中清楚地显示所有事件或过期的交易。这是我的代码。

Active =1 expired =0 仅供您了解

<?php
$query = "SELECT * FROM `subscriptions` WHERE `username` = '$username'";
$result = mysqli_query($con, $query) or die(mysqli_error($con));

while ($row = mysqli_fetch_array($result))
{
if ($row['active'] == 1)
{
$status = "Active";
$transid = $row['txn_id'];
$transdate = date('F j, Y',strtotime($row['date']));
$subid = $row['id'];
$payment = $row['payment'];
}
else
{
$status = "Expired";
$transid = $row['txn_id'];
$transdate = date('F j, Y',strtotime($row['date']));
$subid = $row['id'];
$payment = $row['payment'];
}
}
?>

我使用 if 和 else 来显示状态是活跃还是过期。

我的html代码

<div class="table-responsive">
<table class="table table-striped table-vcenter">
<thead>
<tr>
<th class="text-center">ID</th>
<th class="text-center">PRODUCT</th>
<th class="text-center">STATUS</th>
<th class="text-center">DATE</th>
<th class="text-center">PAYMENT</th>
<th class="text-center">TRANSACTION ID</th>
</tr>
</thead>


<?php
echo'
<tbody class="text-center">

<tr>
<td>'.$subid.'</td>
<td>'.$package.'</td>
<td>'.$status.'</td>
<td>'.$transdate.'</td>
<td>'.$payment.'</td>
<td>'.$transid.'</td>
</tr>
</tbody>';
?>
</table>
</div>

例如,这里有一些上限,我想始终显示订阅是否仍然有效,因为显然这是历史

active subscription问题是,如果用户订阅过期,则不会显示在历史记录中,只会显示最后 1 个

过期时在这里 expired subscription

最佳答案

我的版本:)

PHP

$query = "SELECT * FROM `subscriptions` WHERE `username` = ?";
$queryStmt = $con->prepare( $query );

if ( $queryStmt )
{
$queryStmt->bind_param( "s", $username ); // <-- This prevents SQL injection and may be handy for executing the query several time more efficiently
$queryStmt->execute();
$queryStmt->bind_result( $active, $transid, $date, $subid, $payment, $package ); // <-- the order must match the order of the fields in the $query

$rows = []; // <-- load here the content fo the DB rows
while( $queryStmt->fetch() )
{
// Transform needed variables

$status = ( $active == 1 ) ? "Active" : "Expired";
$transdate = date( 'F j, Y', strtotime( $date ) );

$rows[] = compact( 'satus', 'transid', 'transdate', 'subid', 'payment', 'package' );
}

$queryStmt->close();
}

HTML

    <div class="table-responsive">
<table class="table table-striped table-vcenter">
<thead>
<tr>
<th class="text-center">ID</th>
<th class="text-center">PRODUCT</th>
<th class="text-center">STATUS</th>
<th class="text-center">DATE</th>
<th class="text-center">PAYMENT</th>
<th class="text-center">TRANSACTION ID</th>
</tr>
</thead>
<tbody class="text-center">
<?php foreach( $rows as $row ) : ?>
<tr>
<td><?php echo $row['subid'] ?></td>
<td><?php echo $row['package'] ?></td>
<td><?php echo $row['status'] ?></td>
<td><?php echo $row['transdate'] ?></td>
<td><?php echo $row['payment'] ?></td>
<td><?php echo $row['transid'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
?>
</table>
</div>

关于php - 试图创造交易历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44193695/

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