Page 1 of 2 1 2 LastLast
Results 1 to 15 of 18

Thread: Count total of records

  1. #1
    Join Date
    Jan 2004
    Location
    JB
    Posts
    4
    Rep Power
    0

    Count total of records

    salam sejahtera..
    saya bdak baru blajar php...
    kalau tak keberatan leh tumpang tanya tak?
    ape care/scripts/function yg paling senang tuk 'sum'kn jumlah rekod dlm db (mysql - dlm satu table.)?
    thanks...
    regards

  2. #2
    Join Date
    Oct 2001
    Location
    Melbourne, AU
    Posts
    456
    Rep Power
    230
    PHP Code:
    $db //db connection

    $sql mysql_query("SELECT * FROM table"$db);
    $rows mysql_num_rows($sql);

    //echo $rows; 

  3. #3
    Join Date
    Jan 2004
    Location
    JB
    Posts
    4
    Rep Power
    0
    thanks.. but
    PHP:--------------------------------------------------------------------------------
    $db = //db connection

    $sql = mysql_query("SELECT * FROM table", $db);
    $rows = mysql_num_rows($sql);

    //echo $rows;

    perhaps it works.....

    mysql_num_rows kite bleh dapatkan jumlah rekod atau bil rekod yg affect ngan query?

    apa beza ngan "select count(nama medan) from nama table";
    thanks so much!!!

    refards

  4. #4
    Join Date
    Oct 2001
    Location
    Melbourne, AU
    Posts
    456
    Rep Power
    230
    PHP Code:
    $sql mysql_query("SELECT COUNT(Key) FROM table");
    $rows mysql_result($sql$db);

    //echo $rows; 
    There isn't much difference between that example and the one earlier if your not running a large database.

    The performance factor between the two methods is negligible for a small database.

  5. #5
    Join Date
    Jan 2004
    Location
    JB
    Posts
    4
    Rep Power
    0
    maybe my question does not so clear... what is really i want to ask is there any easiest way to 'sum' (count the sum) of your records in the db?
    let say that
    user vol
    abu 5
    abu 8
    abu 9
    ali 9

    is a record on db.....
    >> the sum of vol for abu is 22 right?
    so... how can i get these '22'?

    thanks.

  6. #6
    Join Date
    Oct 2001
    Location
    Melbourne, AU
    Posts
    456
    Rep Power
    230
    Ic,

    for this example we will have 2 fields:
    Name (abu, ali, etc.) and
    Number (5,9, etc.)

    The easiest way is to do something like the following:

    PHP Code:
    $final 0;

    $db = ... ;

    $sql mysql_query("SELECT * FROM table WHERE Name='abu'");
    while (
    $output mysql_fetch_array($sql)) {
        
    $final $final $output['Number'];
    }

    echo 
    $final
    I haven't tested the code, but i'm quite sure it should work.

  7. #7
    Join Date
    Oct 2001
    Location
    Kuala Lumpur, Malaysia
    Posts
    296
    Rep Power
    226
    Use this SQL
    Code:
    $sql = "select sum(vol) where user like 'abu'";
    Why ... ?? Whenever possible, put the data calculation at the db server. Great advantage especially when webserver & db server are two different machine. Second, when dealing with text or string, use LIKE rather than "=".
    Last edited by kidino; 20-01-2004 at 10:39 AM.
    --------------------------------------------
    Khairil Iszuddin Ismail

  8. #8
    Join Date
    Jan 2003
    Location
    dreamland
    Posts
    240
    Rep Power
    210
    btul tuh..
    better buat kat sql query.. then buat count on looping...
    jeb23 try ler sql query tuh...
    mesti jadik nyer..
    hahahahha...
    ^_^ <== stay happy

  9. #9
    Join Date
    Jan 2004
    Location
    JB
    Posts
    4
    Rep Power
    0
    mr sufyan, kidino......
    saya dah try dua2.. both code dapat result yg sama.....
    thanks so much!!!!!!!!!!

  10. #10
    Join Date
    Jan 2003
    Location
    dreamland
    Posts
    240
    Rep Power
    210
    ini pandangan aku ler... <== korang boleh celah kalau aku silap

    result memang sama, tp lebih ekfisien (btul ke eja ni ) kalau guna terus kat query. sbb nak elak looping while tuh... so aku rasa lg cepat guna query tuh... cepat skit ler.. bukan byk pun.. hihihik

    btul tak? ker salah?
    ^_^ <== stay happy

  11. #11
    Join Date
    Oct 2001
    Location
    Melbourne, AU
    Posts
    456
    Rep Power
    230
    That is correct. Using the direct query method does eliminate a process and does improve efficiency. However, the improvement in performance between the two methods are negligible for a small database.

    The example given in this topic is very basic. If you needed a more complex function, the second method would be of more use as you could intergrate the power of PHP to manipulate your data.

    As for 'LIKE' rather than "=", I disagree with that statement as the equal sign (=) is the equivalent of IN in SQL, which returns exact matches.

    LIKE is better used for a pattern with wildcards (%).

    Anyhow, both methods will work ('IN' - = or 'LIKE' - without wildcards %), and there are no performance differences between the two.

  12. #12
    Join Date
    Nov 2001
    Location
    Johor
    Posts
    772
    Rep Power
    235
    ya ya! walaupun dah pakai zend optimize =)
    I hate when:

    vBulletin Message:
    Sorry! The administrator has specified that users can only post one message every 60 seconds

  13. #13
    Join Date
    Jan 2003
    Location
    dreamland
    Posts
    240
    Rep Power
    210
    Originally posted by hymns
    ya ya! walaupun dah pakai zend optimize =)
    aku tak ler hustler sgt..
    so aku nak tanya ler..
    zend optimize tu buat aper?
    aper function dier dlm php?
    aku dah baca skit review dier.
    tp tak paham
    ^_^ <== stay happy

  14. #14
    Join Date
    Nov 2001
    Location
    Johor
    Posts
    772
    Rep Power
    235
    aler tambah performance bg yg run server lah.. tapi kalau small / developer x rasa beza pong...
    I hate when:

    vBulletin Message:
    Sorry! The administrator has specified that users can only post one message every 60 seconds

  15. #15
    Join Date
    Jan 2003
    Location
    dreamland
    Posts
    240
    Rep Power
    210
    Ooo..
    benda tuh kena install kat server ker..
    aku ingat dier cam ader panggil some other component..

    ok tq
    ^_^ <== stay happy

Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Kaspersky Kung Fu Lab (MALAYSIA BOOK OF RECORDS)
    By Laughingman in forum Mamak Stall
    Replies: 0
    Last Post: 30-07-2009, 10:16 AM
  2. Custom DNS Records
    By tansks in forum Webmaster Tools
    Replies: 2
    Last Post: 21-06-2009, 02:03 PM
  3. A total noob
    By kenx76 in forum Member Introductions
    Replies: 3
    Last Post: 07-11-2007, 08:40 AM
  4. Post count not showing in categories WP
    By iamfreelancer in forum Blogging Discussion
    Replies: 3
    Last Post: 30-10-2007, 10:37 AM
  5. Visitor's Count
    By patcjh in forum Website Programming
    Replies: 12
    Last Post: 24-01-2007, 05:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112