Php mysql_fetch_object:获取一个对象和下一个对象?
我有一个项目列表,这些是路线上的点。这就是我想要实现的目标:Php mysql_fetch_object:获取一个对象和下一个对象?,php,mysql,loops,Php,Mysql,Loops,我有一个项目列表,这些是路线上的点。这就是我想要实现的目标: <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> A点-B点 B点-C
<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>
- A点-B点
- B点-C点
- C点-D点
- D点-E点
但是,我只知道一旦这样做了,如何使其中一个恢复正常:
while($row=mysql_fetch_object($res)){
echo'<li>'.$row->title.'</li>';
}
while($row=mysql\u fetch\u object($res)){
回显“”.$row->title.“ ”;
}
我能在同一个环路上得到两点吗?我应该如何通过循环来获得一个点和下一个点?(我的sql查询给我按如下顺序排列的点:点A、点B、点C、点D、点E)//请注意,这至少需要两行才能工作。
//如果您不确定,请在运行之前检查mysql_num_行。
$first=mysql\u fetch\u对象($res);
$second=mysql\u fetch\u对象($res);
做{
//对这两排做点什么
//就你而言:
回显“”.$first->title.-”.$second->title.“ ”;
//将第二行移到第一行
$first=$second;
}而($second=mysql_fetch_object($res));
您可以发布当前查询吗?
//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));
while($row=mysql_fetch_object($res)){
$myresult[] = $row->title;
}
foreach( $myresult as $key=>$value ){
echo $value->title . ( isset( $myresult[$key+1] ) ? ( '-'. $myresult[$key+1]->title ): '' );
}