<?
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database",$db);
$sql = "SELECT COUNT(*) FROM table";
$result = mysql_query($sql);
echo "$result";
?>
This returns "Resource id #3". All it should say is '2'. Can anyone tell me
what I'm doing wrong?
Thanks,
Matt
What makes you think that mysql_query should return 2?
Please read the manual: http://uk.php.net/mysql_query
The next to last paragraph in particular.
"Only for SELECT,SHOW,DESCRIBE or EXPLAIN statements, mysql_query() returns a
new result identifier that you can pass to mysql_fetch_array() and other
functions dealing with result tables."
etc.
--
Andy Hassall (an...@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
You want to use:
mysql_num_rows($result);
http://www.php.net/manual/en/function.mysql-num-rows.php
Todd
Use mysql_num_rows($result) when your query is "SELECT * FROM table";
If your query is "SELECT COUNT(*)...", use
$sql = "SELECT COUNT(*) FROM table";
$result = mysql_query($sql);
$num = mysql_result($result, 0);
echo $num;
---
"If there is a God, he must be a sadist!"
Email: rrjanbiah-at-Y!com