I have found a reference in the tutorials that this 0 returns the first row but I "Don't Get It" What if there's more than 1 row such as in the function below?? (ie: I have a table of 200 users and this column "UsersName" is just one among 10 others so why the Zero?)
Could someone please spell out why this 0 is in this line of code??
Thanks
function member_count() {
return mysql_result(mysql_query("SELECT COUNT(`UsersName`) FROM `users` WHERE `Active` = 1"), 0);
}
Couldn't you have looked up the PHP documentation? It's rather good...
string mysql_result ( resource $result , int $row [, mixed $field = 0 ] )
row
The row number from the result that's being retrieved. Row numbers start at 0.
http://php.net/manual/en/function.mysql-result.php
Imagine you done a SELECT * FROM users
, where the table contains
name | age
David | 29
John | 18
Paul | 26
Row 0 would be "David - 29", row 1 would be "John - 18", so forth.
look this page
http://php.net/manual/en/function.mysql-result.php
mysql_result ( resource $result , int $row [, mixed $field = 0 ] )
Retrieves the contents of one cell from a MySQL result set.
When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
result
The result resource that is being evaluated. This result comes from a call to `mysql_query().`
row
The row number from the result that's being retrieved. Row numbers start at 0.
field
The name or offset of the field being retrieved.
It can be the field's offset, the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name. If undefined, the first field is retrieved.
Right, it returns the first row. The query you've posted also returns one row. Read about the function COUNT() in MySQL.
You also can use that for several reasons, i.e. if the first row is also the admin user in users table and you only need it, no matter what's the autoincrement ID or username/password, etc.