简体   繁体   中英

how read two records at once from sql select query results?

我希望每次从PHP中选择查询结果读取两条记录?

like this:

while($row1 = mysql_fetch_array($result))
{
  $row2 = mysql_fetch_array($result);
  // Do something
}

EDIT:

Then it would be like this

$row1 = mysql_fetch_array($result);
while($row2 = mysql_fetch_array($result))
{
  // Do something
  $row1 = $row2
}

As you wrote in comment:

i want to do somthing with each twic recodes .. like this .. 1 with 2, 2 with 3, 3 with 4 ... but this let me 1 with 2 , 3 with 4, ..

$row1 = mysql_fetch_array($result);
if($row1 != false){
  while($row2 = mysql_fetch_array($result);)
   {
     // do something

      $row1 = $row2 ;
  }


}

The mysql_query engine for PHP only supports single queries. You'll need to execute each query separately.

I think, UNION can help you. It would fetch you the two records in a single query execution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM