Results 1 to 5 of 5
  1. #1

    How To Display COUNT(*) result Via The Alias ?

    How To Display COUNT(*) result Via The Alias ?


    Php Programmers,

    I have learnt from you guys to use the COUNT(*) over the num_rows or mysqli_stmt_num_rows if I simply want to get the matching row counts and not the rows data aswell.
    Now, I'm having great trouble in echoing on screen the matching rows found by the COUNT(*) and so how to do this ?
    I am trying to return the result via the COUNT(*) alias. In my case "total". Now, how to do this ?
    And, if you don't return the result via the alias then how do you return it then ? I'd like to see 2 code samples. One where the result is returned by the alias and another example where not returned by the alias.

    Thank You

    Anyway, here are my 4 failing attempts:


  2. #2

    How To Display COUNT(*) result Via The Alias ?

    Yeah, I know. The last ones look really pathetic. But you can't blame me for trying. Even though I am googling now. I have failed so far to find the answers with my keywords. Plus, I want to learn how you code it. Learn your ways.


    Note that, on the above 4 codes, I am not using PREP STMT since PREP STMT is not needed on those.
    I know how to display the COUNT(*) result via PREP STMT. Correct me if I am wrong but I would do it like this:

    PHP Code:
    $query_1 = "SELECT COUNT(*) as total FROM notices WHERE recipient_username = ? AND sender_username = ?";
    $stmt_1 = mysqli_prepare($conn, $query_1);
    mysqli_stmt_bind_param($stmt_1,'ss',$recipient_username,$sender_username);
    mysqli_stmt_execute($stmt_1);
    $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count);
    mysqli_stmt_fetch($stmt_1);
    mysqli_stmt_free_result($stmt_1);
    printf(" %d rows found.\n",$matching_rows_count);


    Anyway, I need to learn how to do it without PREP STMT as I have come to a point where PREP STMT is not needed in my query.
    Any tips or hints ? Even a good link would do me fine.
    Bear in mind: I not want to use mysqli_num_rows but the count(*). I need to see a code sample from somewhere to get an idea how to do things.

    Cheers!

  3. #3

    How To Display COUNT(*) result Via The Alias ?

    It's the same ****ing process.... how are you this dense? If you don't have anything to "bind", then don't bind, but the process is the ****ing same.

    PHP Code:
    $query_1 = "SELECT COUNT(*) as dumbmfer FROM browsing_histories";
    $stmt_1 = mysqli_prepare($conn, $query_1);
    //mysqli_stmt_bind_param($stmt_1,'ss',$recipient_use rname,$sender_username);
    mysqli_stmt_execute($stmt_1);
    $result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count);
    mysqli_stmt_fetch($stmt_1);
    mysqli_stmt_free_result($stmt_1);
    printf(" %d rows found.\n",$matchi


  4. #4

    How To Display COUNT(*) result Via The Alias ?

    Originally Posted by Sepodati
    how are you this dense?



    You haven't figured this out yet? Just stop feeding it.


    There are 10 kinds of people in the world. Those that understand binary and those that don't.

  5. #5

    How To Display COUNT(*) result Via The Alias ?

    Originally Posted by gw1500se
    You haven't figured this out yet? Just stop feeding it.

    I know... there's nothing else going on here, though...


    -- Cigars, whiskey and wild, wild women. --

Posting Permissions

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