how do i get mysql_num_rows from a php function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andreea115
Forum Newbie
Posts: 9
Joined: Tue Aug 23, 2011 6:18 am
Location: United Kingdom

how do i get mysql_num_rows from a php function

Post by andreea115 »

Hi everyone.

How do i get the mysql_num_rows from a php function; i wish to use the extracted number with my page pagination.

i know that if i do the following i will get the num rows.

Code: Select all


$sql = mysql_query("SELECT id,  FROM Members WHERE email_activated='1' ORDER BY id ASC"); 
$nr = mysql_num_rows($sql);  

i also know that if i place the same in a function i can simply question the Mysql Num rows after the query is run. e.g

Code: Select all

function  nationality_list (    )
         
         {
             global $dbc;
            $select = "  SELECT  
                        id                                        
                      $from   = "    FROM
            Members ";
            
          $query = $select.$from  ;     
         $result = mysqli_query ($dbc, $query);        
          $nr = mysql_num_rows($result);
             return $result ;         
        
              }  
two questions;

1. is this the correct way to get the num rows

2. if so , how do i extract the number from the PHP function.

is it possible to do two returns from a function. i.e

Code: Select all

$result = mysqli_query ($dbc, $query);        
          $nr = mysql_num_rows($result);
             return $result ;         
             return  $nr ;  

warm regards

andreea
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: how do i get mysql_num_rows from a php function

Post by requinix »

1. Yes.
2. Return the resultset (what you got from mysql_query()) and let the code calling your function use mysql_num_rows() if it wants to itself.
Post Reply