downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

mysqli_driver> <mysqli_result::$lengths
[edit] Last updated: Fri, 17 May 2013

view this page in

mysqli_result::$num_rows

mysqli_num_rows

(PHP 5)

mysqli_result::$num_rows -- mysqli_num_rowsObtiene el número de filas de un resultado

Descripción

Estilo orientado a objetos

Estilo por procedimientos

int mysqli_num_rows ( mysqli_result $result )

Retorna el número de filas del resultado.

El comportamiento de mysqli_num_rows() depende de si es que se utilizan resultsets con o sin buffer. En caso de emplearlos sin buffer mysqli_num_rows() no retornará el número de filas correcto hasta que todas las filas del resultado hayan sido recuperadas.

Parámetros

result

Sólo estilo por procedimientos: Un conjunto de identificadores de resultados devuelto por mysqli_query(), mysqli_store_result() o mysqli_use_result().

Valores devueltos

Retorna el número de filas del resultado.

Nota:

Si el número de filas es mayor al máximo valor de MAXINT, el número será retornado como un string.

Ejemplos

Ejemplo #1 Estilo orientado a objetos

<?php
$mysqli 
= new mysqli("localhost""my_user""my_password""world");

/* verificar la conexión */
if (mysqli_connect_errno()) {
    
printf("Conexión fallida: %s\n"mysqli_connect_error());
    exit();
}

if (
$result $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name")) {

    
/* determinar el número de filas del resultado */
    
$row_cnt $result->num_rows;

    
printf("Result set has %d rows.\n"$row_cnt);

    
/* cerrar el resultset */
    
$result->close();
}

/* cerrar la conexión */
$mysqli->close();
?>

Ejemplo #2 Estilo por procedimientos

<?php
$link 
mysqli_connect("localhost""my_user""my_password""world");

/* verificar la conexión */
if (mysqli_connect_errno()) {
    
printf("Conexión fallida: %s\n"mysqli_connect_error());
    exit();
}

if (
$result mysqli_query($link"SELECT Code, Name FROM Country ORDER BY Name")) {

    
/* determinar el número de filas del resultado */
    
$row_cnt mysqli_num_rows($result);

    
printf("El resultado tiene %d filas.\n"$row_cnt);

    
/* cerrar el resulset */
    
mysqli_free_result($result);
}

/* cerrar la conexión */
mysqli_close($link);
?>

El resultado de los ejemplos serían:

El resultado tiene 239 filas.

Ver también



add a note add a note User Contributed Notes mysqli_result::$num_rows - [2 notes]
up
0
borisigna
1 year ago
If you have problems making work this num_rows, you have to declare ->store_result() first.

<?php
$mysqli
= new mysqli("localhost","root", "", "tables");

$query = $mysqli->prepare("SELECT * FROM table1");
$query->execute();
$query->store_result();

$rows = $query->num_rows;

echo
$rows;

// Return 4 for example
?>
up
-1
jonteh at zaphotel dot net
1 year ago
<?php

   
class mysqlisimple extends mysqli {
        public function
__construct($hostname, $username, $password, $database) {
           
$this->connection = @parent::__construct($hostname, $username, $password, $database);
            if(
$this->connection->connect_error) {
                die(
$this->connection->connect_error);
            }
        }
        public function
DBResult($query) {
           
$this->PrepareQuery = $query;
            if (
$this->Result = $this->query($this->PrepareQuery)) {
                while (
$this->row = $this->Result->fetch_row()) {
                   
$this->output = $this->row[0];
                }
            }
            return
$this->output;
        }
    }
   
?>

This is a simple class to extend MySQLi and includes a function to fetch a single result. Was just playing, thought it may help some.

 
show source | credits | sitemap | contact | advertising | mirror sites