0

Hello everybody
I'm working on MySQL
I always have to use the Count function like this:

$Q = mysql_query("Select count() from tableA",$connection);

How can I handle this query? How can I handle the number returned by this query??
Thanks.

5
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Paaat
0
$total = mysql_query("SELECT COUNT(*) FROM $table_and_query"); 
        $total = mysql_fetch_array($total);

You can also try this one

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

Edited by MooGeek: n/a

0

$total = mysql_query("SELECT COUNT(*) FROM $table_and_query");
$total = mysql_fetch_array($total);
echo "$num_rows Rows\n";

But $total is an array. So how can I handle it as an integer?

Edited by mike_2000_17: Fixed formatting

0
$total = mysql_query("SELECT COUNT(*) AS mycount FROM $table_and_query"); 
$total = mysql_fetch_array($total);
echo $total['mycount'];
2

You can write the following:

$scc = mysql_query("select count(XXXX) from tableA",$connection);
$sccA = mysql_fetch_array($scc, MYSQL_NUM);
echo $sccA[0];

(Replacing XXXX with a column name).
This should make things work very well.

Edited by Pro2000: n/a

Votes + Comments
It's a direct and concise solution
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.