你如何使用 mysqli_stmt_fetch() 获取 id

How do you GET the id using mysqli_stmt_fetch()

我是新的 mysqli prepared,我将我所有的 mysqli 转换为 mysqli prepared。

我想获取特定数据的 ID,我可以在 mysqli 中轻松地做到这一点。这是我的旧代码:

        echo "<th>".$record['first_name']."</th>";
        echo "<th>".$record['middle_name']."</th>";
        echo "<th>".$record['last_name']."</th>";
        echo "<th>".$record['date_added']."</th>";
        echo "<th>".$record['crew_status']."</th>";
        echo "<th><a target='_blank' href='review.php?id={$record['id']}'>Click</a></th>";
        echo '</tr>';

并且在mysqli中准备好了,这是我的代码:

        while($record = mysqli_stmt_fetch($stmt)) {
        echo "<tr>";
        echo "<th>".sprintf("%s", $col2)."</th>";
        echo "<th>".sprintf("%s", $col3)."</th>";
        echo "<th>".sprintf("%s", $col4)."</th>";
        echo "<th>".sprintf("%s", $col18)."</th>";
        echo "<th>".sprintf("%s", $col19)."</th>";
        echo "<th><a target='_blank' href='review.php?id=$rows[] = $col1'>Click</a></th>";
        echo '</tr>';

下面是我的全部代码:

    $search = 'PENDING';
    $query = "SELECT * FROM `crew_info` WHERE `crew_status` = ?";
    $stmt = mysqli_prepare($conn, $query);
    mysqli_stmt_bind_param($stmt, 's', $search);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $col1, $col2, $col3, $col4, $col5, $col6, $col7, $col8, $col9, $col10, $col11, $col12, $col213, $col14, $col15, $col16, $col17, $col18, $col19);

echo '<!DOCTYPE html>
    <html>
    <head>
        <title>All Crew</title>
    </head>
    <body>
    <form method="POST">
        <table border="2" align="center" width="600" cellspacing="3" cellpadding="4">
            <tr>
                <th>First Name</th>
                <th>Middle Name</th>
                <th>Last Name</th>
                <th>Date Added</th>
                <th>Status</th>
                <th>REVIEW</th>
            </tr>
            <tr>';
            $rows = array();
            while($record = mysqli_stmt_fetch($stmt)) {
            echo "<tr>";
            echo "<th>".sprintf("%s", $col2)."</th>";
            echo "<th>".sprintf("%s", $col3)."</th>";
            echo "<th>".sprintf("%s", $col4)."</th>";
            echo "<th>".sprintf("%s", $col18)."</th>";
            echo "<th>".sprintf("%s", $col19)."</th>";
            echo "<th><a target='_blank' href='review.php?id=$rows[] = $col1'>Click</a></th>";
            echo '</tr>';
          }
         echo '</table>
    </form>
    </body>
    </html>';

改为使用

$rows[] = $col1

为什么不将其更改为仅 $col1?删除 $rows[]

更改您的代码:

    echo "<th><a target='_blank' href='review.php?id=$rows[] = $col1'>Click</a></th>";

到这个

    echo "<th><a target='_blank' href='review.php?id=$col1'>Click</a></th>";