Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts

    num_rows not working

    Can someone tell me what I am doing wrong here?? Just trying to get a simple count and then add 1.

    My table is

    replies
    id - thread - message - author - date - image


    I have 3 rows

    1 - 1 - hello - me - 5/25/13 - me.jpg
    2 - 1 - greetings - you - 5/27/13 - NULL
    3 - 1 - bye - me - 5/28/13 - NULL

    PHP Code:
    $results $mysqli->query("SELECT * FROM replies WHERE thread = $id AND author = $clientID AND image IS NOT NULL");

    $countRows $results->num_rows;
        
    $newNumber $countRows+1;

    echo 
    " $clientID <br> $id <br> $countRows - $newNumber"
    So I am trying to find the # of images posted by me

    My results should be:

    $countRows = 1
    $newNumber = 2
    what I am getting is::
    $countRows =
    $newNumber = 1

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    what are the values in $id and $clientID
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    In your table dump, you show the author field as containing string values:
    me
    you
    me

    Yet in your query, you are treating the field as containing a *NUMBER*:
    AND author = $clientID

    Which is it? If you really have a string value ("me", "you") then clearly you are never going to get a match on $clientID, which is just as clearly a number (since you don't have '...' around the value and it doesn't cause a syntax error, apparently).

    EDIT: Yea, what Felgall asked. Only I'm more long-winded. <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Jun 2010
    Location
    Earth
    Posts
    305
    Thanks
    27
    Thanked 2 Times in 2 Posts
    That was the problem, I was treating it incorrectly

    Thanks!


  •  

    Posting Permissions

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