Mysqli fetch_assoc 第一个结果

Mysqli fetch_assoc 第一个结果

问题描述:

我有一个 fetch_assoc 查询,它将抓取 14 行,但我希望显示第一个结果,因此它与其他结果不同,其余的都是普通的.

I have a fetch_assoc query that will grab 14 rows, but I want the FIRST result displayed so it is differnet to the others, then the rest are just ordinary.

    $site_events = $db->query("SELECT * FROM site_events ORDER BY time ASC limit 14");
        while($events = $site_events->fetch_assoc()) {

        if( first result???? ) { //this is where im stuck
           echo $events['title'], 'FIRST RESULT';
        }

        //then display others like a normal list..
        echo $events['title'], '<br />';
   }

您可以在while"之外获取第一行,然后正常继续.但首先您应该检查是否有选择的数据以防万一:

You can fetch first line outside the "while" and then continue normally. But first you should probably check if there are data selected just in case:

$site_events = $db->query("SELECT * FROM site_events ORDER BY time ASC limit 14");
if($db->field_count){
   $event = $site_events->fetch_assoc();
   echo $event['title'], 'FIRST RESULT';

   while($events = $site_events->fetch_assoc()) {

     //then display others like a normal list..
     echo $events['title'], '<br />';
   }
}