带有来自 sql 数据库的值的表没有出现

我写了这段代码,它应该用用户兑换的所有代金券和它们的价值制作一个表格,但它不起作用(根本没有出现,也没有显示任何错误)所以我很困惑我在这里做错了什么. 有人可以帮忙吗?


$dsn = 'mysql:host=127.0.0.1;dbname=user_db;charset=utf8';


$conn = new PDO($dsn, $username1, $password);

$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$stm_voucher = $conn->prepare("SELECT id FROM users WHERE username = :username");

$stm_voucher->bindParam(":username", $username, PDO::PARAM_INT);

$stm_voucher->execute();


while ($row = $stm_voucher->fetch(PDO::FETCH_ASSOC)) {

    $id = $row["id"];


    $stm_voucher2 = $conn->prepare("SELECT * FROM vouchers WHERE used_by = :id");

    $stm_voucher2->bindParam(":id", $id, PDO::PARAM_INT);

    $stm_voucher2->execute();


    $rank = 1;

    while ($row2 = $stm_voucher2->fetch(PDO::FETCH_ASSOC)) {

        echo "<tr>

            <td>{$rank}</td>

            <td>{$row2['voucher']}</td>

            <td>{$row2['value']}</td>

            <td>{$row2['used_on']}</td>

            </tr>";

        $rank++;

    }

}


杨魅力
浏览 95回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript