gpt4 book ai didi

php - mysql_fetch_object : get one and object and the next one?

转载 作者:行者123 更新时间:2023-11-29 09:07:34 24 4
gpt4 key购买 nike

我有一个项目列表,这些是路线的点。这就是我想要实现的目标:

  <ul>
<li>Point A - Point B</li>
<li>Point B - Point C</li>
<li>Point C - Point D</li>
<li>Point D - Point E</li>
</ul>

但话又说回来,我只知道如何在执行此操作后将其中一个按顺序排列:

   while($row=mysql_fetch_object($res)){
echo'<li>'.$row->title.'</li>';
}

我可以得到同一个循环上的两个点吗?我应该如何遍历它以获得一个点和下一个点? (我的 sql 查询给出了按如下方式排序的点:A 点、B 点、C 点、D 点、E 点)

最佳答案

//Note that this requires at least two rows to work.
//Check with mysql_num_rows before running this if you are unsure.
$first = mysql_fetch_object($res);
$second = mysql_fetch_object($res);

do {

//do something with the two rows here
//in your case:
echo'<li>'. $first->title .' - '. $second->title .'</li>';

//Move the second row to be the first
$first = $second;
} while($second = mysql_fetch_object($res));

关于php - mysql_fetch_object : get one and object and the next one?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6621333/

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