Discuss Displaying number of items in mysql database in the PHP Development forum on Dev Shed. Displaying number of items in mysql database PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 12
Time spent in forums: < 1 sec
Reputation Power: 0
Hi can any one tell me please why i keep getting a value of 2 when i include this scipt (i know i have over 200 items)it works fine from a mysql prompt as select count(FIELD) from table; gives correct result
but this in php gives a result of 2 ?
$item_count = "SELECT count(FIELD)FROM table";
$item_result = mysql_query($item_count)
or die("Couldn't get count");
Posts: 63
Time spent in forums: < 1 sec
Reputation Power: 12
The result your getting is the integet id of the result, not the result itself. For example, if I run a query against the database
$connection = mysql_connnect($host,$user,$pwd);
echo $connection; // This will be an integer identifier for a php connection
$result = mysql_query("select * from customers", $connection);
echo $connection; // This will be an integer identifier for a php result set
// Now you need to get the data out of the result set....
$last_name = mysql_result($result, 0, "last_name"); // where 0 is the first row in the result set
// So to get your query to work properly,
//you need to read out the result as I did
//above but remember to name the field
//otherwise you have to access it by offset
//and not by name
$result = mysql_query("select count(*) as mycount from customers", $connection);