php - 试图创造交易历史

标签 php mysql

大家好,我正在尝试制作交易历史记录,当然是从数据库中获取类(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/

相关文章:

PHP : $_GET is not retrieving data from MySQL database

php - 模式搜索的 Ajax 回调问题

php - 菜单图像对齐

php - MySql 搜索脚本写入未知错误

mysql - 我无法填充我的 MySQL 表

mysql - BitNami WordPress 安装搞砸了 ApacheFriends XAMPP 控制面板

php - InnoDB 数据库表耗时 51 秒

Phpass - 如何根据数据库中的用户名和密码哈希检查登录用户名和密码

php - 使用新的 YouTube API v3 解析 YouTube 订阅者数量

PHP:如何将mysql到excel文件保存到目录而不提示用户下载