doulin9679 2016-05-24 02:10
浏览 29
已采纳

你如何使用mysqli_stmt_fetch()[关闭]获取id

im new in mysqli prepared and i convert all my mysqli to mysqli prepared.

i want to get the id of the specific data and i can easily do that in mysqli. here is my old code:

        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>';

and in the mysqli prepared, this is my code:

        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>';

below is my entire code:

    $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>';
  • 写回答

1条回答 默认 最新

  • doushi8187 2016-05-24 02:20
    关注

    instead using

    $rows[] = $col1
    

    why don you change it to $col1 only? remove the $rows[]

    change your code from:

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

    to this

        echo "<th><a target='_blank' href='review.php?id=$col1'>Click</a></th>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度