简体   繁体   中英

Mysql Select Second Row from 1 query

How do you do so we can get to the line 2 of the query in fetch?

Query : select * from news where id_category_news = '1'

I use a while for query

while($event_res = mysqli_fetch_array($event_query))

I want

Row 1 will take to :

                        echo '<article class="post">
                            <a class="image_thumb_zoom" href="#" title="'.$event_res['title_news'].'">
                            <img width="371" height="177" src="dist/images/dummy/shutterstock_58382248-371x177.jpg" class="attachment-post-first wp-post-image" alt="shutterstock_58382248">
                            </a>
                            <h4 class="post-title">
                            <a href="#" title="'.$event_res['title_news'].'">'.$event_res['title_news'].'</a>
                            <span class="date">'.TimetoDate($event_res['time_news']).'</span>
                            </h4>
                            <p>'.$event_res['text_news'].'</p>
                        </article>
                        ';

and row 2 :

                            <article class="post">
                                <div class="entry clearfix">
                                    <a href="#" title="Permalink to Nam nibh arcu tristique eget pretium vitae libero ac risus" rel="bookmark">
                                    <img width="225" height="136" src="dist/images/dummy/photodune-3517559-idea-s-225x136.jpg" class="thumb wp-post-image" alt="photodune-3517559-idea-s">
                                    <h4 class="post-title">Nam nibh arcu tristique eget pretiu...</h4>
                                    </a>
                                    <p>Nam nibh arcu, tristique eget pretium se...</p>
                                    <div class="meta">
                                        <span class="date">July 2, 2013</span>
                                    </div>
                                </div>
                            </article>

Why don't you have an integer that increases as it goes through the rows like so:

$row = 1;

while($event_res = mysql_fetch_assoc($event_query)) {
   //do something here...

   if ($row == 1) {
      // do row 1 things here...

   } else if ($row == 2) {
      // do row 2 things here...
   }

   $row++;
}

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