count

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
superman
Forum Commoner
Posts: 29
Joined: Tue Jul 08, 2003 2:54 am

count

Post by superman »

is this code correct? but i got this error message 'Resource id #2'


<?
$Connect = mysql_connect("localhost","root","");
mysql_select_db("mw");
$result=mysql_query("select count(StaffID) from LeaveApplication1 where StaffID = 'fui'") ;
echo "$result";
mysql_close();
?>
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

The value of $result is a pointer to your result set returned from your query, you will need a few extra steps to get the data out of your table.

Depending on the amount of data return you will need to use either:

mysql_fetch_row() :
http://uk2.php.net/manual/en/function.m ... ch-row.php

or

mysql_fetch_array() :
http://uk2.php.net/manual/en/function.m ... -array.php

Code: Select all

<? 
$Connect = mysql_connect("localhost","root",""); 
mysql_select_db("mw"); 
$result = mysql_query("select count(StaffID) from LeaveApplication1 where StaffID = 'fui'") ;

$row = mysql_fetch_row($result)
var_dump($row);

mysql_close(); 
?>
There are other methods that you can use, but these are the nost common and should return what you need.

Regards,
Post Reply