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
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    What do I replace the depreciated mysql_num_rows with ?

    Hi,

    I quite often use :

    PHP Code:
    $sql "SELECT page_id,page_type,cat_cd FROM pages WHERE assigned = 'n' ";
    $result mysql_query($sql)    or die("could not find SITE: $site_id"mysql_error());
    $num mysql_num_rows($result);

    if (
    $num ) { 
    I just noticed that the Manual says "mysql_num_rows - This extension is deprecated as of PHP 5.5.0"

    I write php in procedural style rather than OOP.

    What should I use instead of
    $num = mysql_num_rows($result);

    Thanks


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That one would be for statements, while from result you can use mysqli_num_rows. So it depends on if you are preparing a statement or querying directly.
    I should note that since there are two functions and you could do either statements or direct querying, you'd be better of using either the statement's get_result and pulling the mysqli_num_rows off of that, or even better, simply sticking to object oriented as both mysqli_stmt and mysqli_result contain a num_rows property on them.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    depending on the case, SQL’s COUNT() function can be used to avoid the PHP row counting alltogether.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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