Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php+mysql] Pytanie o wyciągnięcie danych z zapytania przed while
tryme
post
Post #1





Grupa: Zarejestrowani
Postów: 83
Pomógł: 0
Dołączył: 5.12.2005

Ostrzeżenie: (0%)
-----


Witam Serdecznie,

Chciałem Was zapytać czy istnieje możliwość aby w poniższym kodzie

  1. <?php
  2. $result = $db->query('SELECT u.email, u.title, u.url, u.location, u.use_avatar, u.signature, u.email_s
    etting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.po
    ster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edit
    ed, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '
    .$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.topic_id='.$id.' ORDER BY p.id LIMIT '.$start_from.','.$pun_user['disp_posts'], true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  3.  
  4. while ($cur_post = $db->fetch_assoc($result))
  5. {
  6. ...
  7. ?>

wstawić tuż przed pętlą while kod wyciągający pierwszą wiadomość
  1. <?php
  2. $cur_post['message'];
  3. ?>

tak aby potem pętla while zaczęła czytać dane od tej pierwszej wiadomości a nie od drugiej?

Dziękuję za pomoc.

Ten post edytował tryme 26.02.2008, 11:10:09
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Grzyw
post
Post #2





Grupa: Zarejestrowani
Postów: 561
Pomógł: 75
Dołączył: 19.08.2004
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Możesz to zrobić na przykład tak:

  1. <?php
  2. $result = $db->query('......');
  3.  
  4. $first = true;
  5.  
  6. while ($cur_post = $db->fetch_assoc($result))
  7. {
  8. if ($first) 
  9.  {
  10.  $currentMsg= $cur_post['message'];
  11.  $first=false;
  12.  continue;
  13.  }
  14.  $mgs[] = $cur_post['message'];
  15. }
  16. ?>


Ten post edytował Grzyw 26.02.2008, 11:29:02
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 16.10.2025 - 01:02