Hello. The database stores records of articles. I want to put them all on the page, and this can be implemented with such code:

$article_all = mysql_query("SELECT * FROM `article` ORDER BY `id` $sort_article LIMIT $otkuda, $set_coll_page"); while ($item = mysql_fetch_assoc($article_all)) { ///тут разметка статьи } 

So, the markup of the article is just a selection of its blocks:

 <div classs="item"> статья </div> 

The question is how for the first article (which has the biggest id), do another markup? that is, select it with other blocks.

I would be very grateful for the help and any useful information.

  • trite counter and if condition ... if the counter is still zero - output such and such a block, otherwise - another - Aleksey Shimansky
  • @ Alexey Shimansky, and what should they say? - iKey
  • the number of iterations inside the while If the first iteration, then do one thing, and if not, the other one is Aleksey Shimansky

2 answers 2

 $article_all = mysql_query("SELECT * FROM `article` ORDER BY `id` $sort_article LIMIT $otkuda, $set_coll_page"); if ($item = mysql_fetch_assoc($article_all)) { // разметка для первой статьи while ($item = mysql_fetch_assoc($article_all)) { // разметка 2-й и последующих статей } } 

PS: mysql_* functions are outdated - do not use them to write new code

  • Why is the comment not in the answer? - Alexey Shimansky
  • So why not in the answer itself ? What is the catch to write an addition to the comments that are intended ..... for comments - Alexey Shimansky

The simplest thing that comes to mind is to enter the flag:

 $First=true; $article_all = mysql_query("SELECT * FROM `article` ORDER BY `id` $sort_article LIMIT $otkuda, $set_coll_page"); while ($item = mysql_fetch_assoc($article_all)) { if ($First) /// альтернативная разметка первой статьи else /// разметка 2-й и последующих статей $First=false; }