Visualizzazione dei risultati da 1 a 5 su 5

Discussione: ciclo per LIMIT

  1. #1

    ciclo per LIMIT

    Ho una pagina che tramite un ciclo prende dal database i primi 5 valori, vorrei che li prendesse dall'ultimo valore inserito.
    Ho un terribile mal di testa e non credo di essermi spiegato benissimo, il codice è:
    Codice PHP:
    $query = "SELECT id,nome FROM eventi";
    $result = mysql_query($query, $db);
    $valore = "0";
    while ($row = mysql_fetch_array($result))

    $valore = $valore + 1;
    }
    $page=1;
    $e=1;
    for ($i=0; $i<$valore; $i=$i+5)
    {
     ?>
                        <span class="paginazione"><font color="#000000"> <?php echo "<a href=view_succ.php?page=$e&valore=$valore&id=$idc>"  ."$e |</a>" ?></font></span>
                        <?php
     
    $e
    =$e+1;
    }
    if (
    $e>2) {
    ?>
                        <span"><? echo "<a href=view_succ.php?page=2&valore=$valore&id=$idc>"  ."></a>" ?>
                        <?php
     
    }

    $a "0";
    $b "5";

    $query "SELECT id,nome,descrizione,miniatura FROM eventi LIMIT $a,$b";
    $result mysql_query($query$db);
    while (
    $row mysql_fetch_array($result))
    {
    ?>
                        <table width="578" height="137" border="0" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
                          <tr>
                            <td height="16" background="immagini/sopra.jpg"></td>
                          </tr>
                          <tr>
                            <td height="100" background="immagini/centrale.jpg" align="center"><table width="535" height="106" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                  <td width="106" valign="bottom"><div align="center">
                                    

    <a href="<?php echo "view_events.php?id=$row[id]?>" >[img]<?php echo [/img]" width="105" height="105" border="0" align="bottom" /></p>
                                  </div></td>
                                  <td width="
    30"><div align="center">[img]immagini/tratteggiosmall.jpg[/img]</div></td>
                                  <td width="
    399" valign="top"><div align="center">
                                    <p align="
    justify"><font size="2">[b]<?php echo "<a href=view_events.php?id=$row[id]>" . "[b]$row[nome][/b]" ; ?>[/b]

                                            <?php echo "
    <a href=view_events.php?id=$row[id]>" . "$row[descrizione]" ; ?></font></p>
                                  </div></td>
                                </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td height="
    15" background="immagini/sotto.jpg"></td>
                          </tr>
                        </table>
    il ciclo è per un impaginazione, ma mi mostra i dati dal primo inserito, come fare per farli leggere dall'ultimo inserito?
    Save the Cheerleader, Save the world.

  2. #2
    Utente di HTML.it L'avatar di thitan
    Registrato dal
    Feb 2001
    Messaggi
    716
    SELECT id,nome FROM eventi ORDER BY id DESC

    www.inter-rail.it
    travellers, not tourist
    Is cuma cá mhinice a théann tú ar strae; is é is tábhachtaí gurb áil leat do bhealach a aimsiú arís.

  3. #3
    e con il limit?
    a me ne deve dare 5 alla volta
    Save the Cheerleader, Save the world.

  4. #4
    che stupido che sono, mettevo l'ORDER dopo il LIMIT -_-'''
    risolto, grazie mille ^_^
    Save the Cheerleader, Save the world.

  5. #5
    Utente di HTML.it L'avatar di thitan
    Registrato dal
    Feb 2001
    Messaggi
    716
    ah è tipo le pagine, allora fai

    SELECT id,nome FROM eventi ORDER BY id DESC LIMIT $da, $quanti

    esempio se devi fare 5 per pagina:

    SELECT id,nome FROM eventi ORDER BY id DESC LIMIT 0, 5 //ultimi 5
    SELECT id,nome FROM eventi ORDER BY id DESC LIMIT 5, 5 //penultimi 5
    SELECT id,nome FROM eventi ORDER BY id DESC LIMIT 15, 5 //e così via

    www.inter-rail.it
    travellers, not tourist
    Is cuma cá mhinice a théann tú ar strae; is é is tábhachtaí gurb áil leat do bhealach a aimsiú arís.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.