tee
tee

Reputation: 155

PHP and MySQL: Number of rows returned

How can I see how many rows the following query returns?

mysql_select_db($database_aoldatabase, $aoldatabase);

$query1 = "select * from sale where secid  = $invoiceno ";
$query2 = "select * from sale where secid  = $invoiceno ";


$maxa = mysql_query ($query1)
    or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');
$maxa2 = mysql_query ($query2)
    or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');

$row = mysql_fetch_array($maxa);
$row2 = mysql_fetch_array($maxa2);

Upvotes: 2

Views: 22352

Answers (2)

Eduard7
Eduard7

Reputation: 746

Like Michiel said, mysql_num_rows() do the job. But if you want to work with more than one rows using an array, you can use count() too.

$data = array();
while($row = mysql_fetch_array($maxa, MYSQL_ASSOC)) {
  $data[] = $row;
}
$count1 = mysql_num_rows($maxa);
$count2 = count($data);

Upvotes: 7

Michiel Pater
Michiel Pater

Reputation: 23053

Use the function mysql_num_rows()

Have a look at: https://www.php.net/manual/en/function.mysql-num-rows.php

Upvotes: 5

Related Questions