Mysqli fetch_assoc 第一个结果 [英] Mysqli fetch_assoc first result

查看:51
本文介绍了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 />';
   }
}

这篇关于Mysqli fetch_assoc 第一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆