Jump to content

Recommended Posts

Okay so a good friend did this for me

/*		
	$memorial = mysql_numrows($database->query("SELECT id FROM users WHERE userlevel ='0'"));
	$fhdirector = mysql_numrows($database->query("SELECT id FROM users WHERE userlevel ='1'"));
	$nonprofile = mysql_numrows($database->query("SELECT id FROM users WHERE userlevel ='2'"));
	$sales = mysql_numrows($database->query("SELECT id FROM users WHERE userlevel ='3'"));
	$support = mysql_numrows($database->query("SELECT id FROM users WHERE userlevel ='4'"));
	$admin = mysql_numrows($database->query("SELECT id FROM users WHERE userlevel ='5'"));
*/

	$SQL = "
	SELECT
		SUM(IF(userlevel='0',1,0)) AS numMemorial,
		SUM(IF(userlevel='1',1,0)) AS numFHDirector,
		SUM(IF(userlevel='2',1,0)) AS numNonProfile,
		SUM(IF(userlevel='3',1,0)) AS numSales,
		SUM(IF(userlevel='4',1,0)) AS numSupport,
		SUM(IF(userlevel='5',1,0)) AS numAdmin
	FROM users";
	$result = $database->query($SQL);
	foreach (mysql_fetch_assoc($result) as $key => $value) {
		$$key = intval($value);	//force string to an integer value
	}

 

 

I am trying to do the same thing but with this table

/*		
	$jan = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 01 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$fen = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 02 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$mar = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 03 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$apr = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 04 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$may = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 05 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$jun = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 06 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$jul = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 07 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$aug = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 08 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$sep = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 09 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$out = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 10 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$nov = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 11 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
	$dec = mysql_numrows($database->query("SELECT id FROM memorial_page WHERE MONTH(FROM_UNIXTIME(timestamp)) = 12 AND YEAR(FROM_UNIXTIME(timestamp)) = $year"));
*/

	$SQL2 = "
	SELECT
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='01',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS jan,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='02',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS fen,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='03',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS mar,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='04',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS apr,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='05',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS may,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='06',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS jun,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='07',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS jul,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='08',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS aug,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='09',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS sep,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='10',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS out,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='11',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS nov,
		SUM(IF(MONTH(FROM_UNIXTIME(timestamp))='12',1,0)) AND YEAR(FROM_UNIXTIME(timestamp)) = $year AS dec
	FROM memorial_page";
	$result2 = $database->query($SQL2);
	foreach (mysql_fetch_assoc($result2) as $key => $value) {  // The error message below is talking about this line
		$$key = intval($value);	//force string to an integer value
	}

 

If anyone can example to me what I am doing wrong is.

 

Here is the error message I get

[15-May-2009 03:48:34] PHP Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/tyslo/public_html/file/panel/charts/admin.php on line 102
[15-May-2009 03:48:34] PHP Warning:  Invalid argument supplied for foreach() in /home/tyslo/public_html/file/panel/charts/admin.php on line 102

 

So if anyone can help me out that would be great.

 

I did this to fix it...

SELECT
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '01' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numjan,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '02' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numfen,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '03' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS nummar,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '04' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numapr,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '05' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS nummay,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '06' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numjun,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '07' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numjul,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '08' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numaug,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '09' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numsep,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '10' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numout,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '11' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numnov,
		SUM(MONTH(FROM_UNIXTIME(timestamp)) = '12' AND YEAR(FROM_UNIXTIME(timestamp)) = $year) AS numdec
	FROM memorial_page

 

 

If you guys know any better way to do it I would love to hear it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.