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

LVL 1
XK8ERAsked:
Who is Participating?
 
PhatzerConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.