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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql_num_rows - returns 0

    I have a rather complex query, with about 3 joins.

    It returns 12 rows when I run the SQL code manually via phpMyAdmin.

    However, when I paste it in my webpage, run the query, and call the

    mysql_num_rows()

    function, it returns 0!

    To double-check, I had the program output the text of the query (with variables filled in, etc.) whenever it gave me "the bad news" that no results were found. I pasted that code into phpMyAdmin and, sure enough, 12 rows!

    The PHP script should be finding 12 rows as well, but it doesn't seem to be!

    The apparent contradiction, and not understanding this behavior of mysql_num_rows, is having me figuratively pulling my hair out. It makes no sense!

    Has anyone else had this problem? If my last 1/2 hour of Googling is any indication, I'm guessing "no".

    Thanks in advance,

    Matthew

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    can you post your code for the call .. e.g.
    PHP Code:
    $q=mysql_query($sql);
    echo 
    mysql_num_rows($q); 
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by ChantCd View Post
    To double-check, I had the program output the text of the query (with variables filled in, etc.) whenever it gave me "the bad news" that no results were found. I pasted that code into phpMyAdmin and, sure enough, 12 rows!

    The PHP script should be finding 12 rows as well, but it doesn't seem to be!
    If your query returns the correct results in phpMyAdmin and not in php then there is a bug in your php code.

    To help see what is happening can you do the following:

    PHP Code:
    $query "select blah blah......";

    echo 
    $query; die(); 
    and post the output of the echo statement.

  • #4
    New Coder
    Join Date
    Jan 2010
    Location
    Birmingham, MI
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    can you post the sql? That will probably tell a lot more

    ...webdev's suggestion will do the same thing.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Firepages!!! You're alive!

    OMG... I bow to thee great oracle of WAMP on USB

    PS When are you gonna update your bl**dy website with some more cool stuff?!?!?!?
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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