gpt4 book ai didi

php - 如何从 php mysql 中获取的行中获取第一个 id?

转载 作者:行者123 更新时间:2023-11-29 18:22:36 25 4
gpt4 key购买 nike

我正在从 mysql 表中获取 php 数据。假设我检索了包含 15 个唯一 ID 的 15 行。现在我想从结果中获取第一个获取的 id。

这就是我正在尝试的..但它给了我最后一个ID

    <?php

$results = $db->query("SELECT * FROM orders where Sales_Rep='$sales_rep'");
while($row = $results->fetch_assoc()){
?>
<tr>
<td><?php echo $row["Order_ID"] ?></td>
<td><?php echo $row["Company_Name"]?></td>
</tr>
<?php
$last_order_date= $row["Order_ID"];
echo $last_order_date;
} //end of while loop
?>

最佳答案

你可以像这样简单地添加索引

$i = 0;

while loop
$i++;
if($i === 1)
{get ID}
//rest of your while loop
endwhile;

关于php - 如何从 php mysql 中获取的行中获取第一个 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46444580/

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