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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2012
    Location
    Delhi
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Why num_rows giving two different result?

    Hi,
    I am little bit confuse with the result of num_rows that i used in my code.
    My table invoice have no value in current because i want to check if no value in the table.
    Here is my code

    code 1 gives $rowc value as 0 that is correct.
    PHP Code:
    $fetch1="select * from invoice"
    $val1=$con->query($fetch1); 
    $rowc=$val1->num_rows
    echo 
    $rowc
    Code 2 gives $rowc value as 1 that is incorrect.
    PHP Code:
    $fetch1="select max(id) as id, order_no from invoice"
    $val1=$con->query($fetch1); 
    $rowc=$val1->num_rows
    echo 
    $rowc
    I just want to know why the result giving two different values.
    Thanks

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    416
    Thanks
    18
    Thanked 26 Times in 26 Posts
    If you use max() in sql queries it will always return a result, whether it's a number or NULL. You'll have to check whether the value is a number or not. Build an array from the results and then var_dump the data to see what you need to do.
    If I've helped you out, show your appreciation by clicking the "Thanks" link as well as a link below!

    AdFly
    Facebook | Twitter
    Google | YouTube


  •  

    Tags for this Thread

    Posting Permissions

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