[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 328
  • Last Modified:

site stats

im trying to show stats for the conent in my site but its not displaying it correctly..
what can I do to fix this?
function dbstats(){
	$dls = array();
	$dls[] = "cats: "      . mysql_query("SELECT count(wcss.id) as numberOfRecords FROM `wcs` WHERE type='cats'");
	$dls[] = " - dogs: "  . mysql_query("SELECT count(wcs.id) as numberOfRecords FROM `wcs` WHERE type='dogs'");
	$dls[] = " - Total: " . mysql_query("SELECT count(wcs.id) as numberOfRecords FROM `wcs`");
 
	foreach ($dls as $result => $value){
		echo $value;
	}
}

Open in new window

0
XK8ER
Asked:
XK8ER
1 Solution
 
PhatzerCommented:
It should be something like this if you're trying to do it inline:
function dbstats(){
        $dls = array();
        $dls[] = "cats: "      . mysql_result(mysql_query("SELECT count(wcss.id) as numberOfRecords FROM `wcs` WHERE type='cats'"), 0, 'numberOfRecords');
        $dls[] = " - dogs: "  . mysql_result(mysql_query("SELECT count(wcs.id) as numberOfRecords FROM `wcs` WHERE type='dogs'"), 0, 'numberOfRecords');
        $dls[] = " - Total: " . mysql_result(mysql_query("SELECT count(wcs.id) as numberOfRecords FROM `wcs`"), 0, 'numberOfRecords');
 
        foreach ($dls as $result => $value){
                echo $value;
        }
}

Open in new window

0
 
Ray PaseurCommented:
Manual Pages show how to understand this.

mysql_query() returns a "Resource ID"
http://us2.php.net/manual/en/function.mysql-query.php

mysql_result() returns the data in ONE cell from a MySQL results set.
http://us2.php.net/manual/en/function.mysql-result.php

Of course, mysql_query() may return FALSE, and in that case you will need to examine the contents of mysql_error() to know what went wrong.

Best regards, ~Ray
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now