Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 31
  1. #1
    Utente bannato
    Registrato dal
    Apr 2004
    Messaggi
    1,392

    [Mysql]Contare tutti i record nella tabella

    Ciao raga, vorrei farvi questa stupidissima domanda:
    Come faccio a contare tutti i record presenti in una tabella??
    Non so che query passare a mysql_fetch_array(), visto che non mettendo il where non funziona... Forse si potrebbe fare con mysql_fetch_row() ma non so che query passargli...
    In attesa di luminari...


  2. #2
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    "SELECT COUNT(campo) FROM tabella";
    think simple think ringo

  3. #3
    Utente bannato
    Registrato dal
    Apr 2004
    Messaggi
    1,392
    Originariamente inviato da marketto
    "SELECT COUNT(campo) FROM tabella";
    come campo ne posso mettere anche uno a caso, no?

  4. #4
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    si, basta che effettivamente sia un campo della tabella della quale vuoi il numero di records
    think simple think ringo

  5. #5
    Utente bannato
    Registrato dal
    Apr 2004
    Messaggi
    1,392
    Originariamente inviato da marketto
    si, basta che effettivamente sia un campo della tabella della quale vuoi il numero di records
    quindi...
    Codice PHP:
    //voglio sapere tutti i record della tabella guestbook
    $a "SELECT COUNT(campo) FROM tabella";
    //Questa query a cosa la devo pasare?
    //mysql_fetch_array() o mysql_fetch_row()??? 

  6. #6
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    $st=mysql_query("SELECT COUNT(campo) AS totale FROM tabella") or die(mysql_error());
    $row=mysql_fetch_assoc($st);
    echo $row['totale'];
    think simple think ringo

  7. #7
    Usa COUNT(*), è più veloce

    COUNT(*) is somewhat different in that it returns a count of the number of rows retrieved, whether or not they contain NULL values. COUNT(*) is optimized to return very quickly if the SELECT retrieves from one table, no other columns are retrieved, and there is no WHERE clause. For example:

    mysql> SELECT COUNT(*) FROM student;

    This optimization applies only to MyISAM and ISAM tables only, because an exact record count is stored for these table types and can be accessed very quickly. For transactional storage engines (InnoDB, BDB), storing an exact row count is more problematic because multiple transactions may be occurring, each of which may affect the count.
    Addio Aldo, amico mio... [03/12/70 - 16/08/03]

  8. #8
    Originariamente inviato da gm
    Usa COUNT(*), è più veloce
    infame!!!
    w la topa

  9. #9
    Originariamente inviato da saibal
    infame!!!
    Addio Aldo, amico mio... [03/12/70 - 16/08/03]

  10. #10
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Non solo è più veloce, ma se metti COUNT(campo) e campo contiene valori NULL, il risultato sarà diverso.

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.