Page 1 of 1

MySQL problem... "not a valid result resource"

Posted: Fri May 30, 2008 7:57 pm
by jkashu

Code: Select all

// Get clicks
$clicks = mysql_query("SELECT
                      SUM(CASE WHEN clickdate = CURDATE() THEN 1 ELSE 0) AS 'numtoday',
                      SUM(CASE WHEN WEEK(clickdate) = WEEK(CURDATE()) THEN 1 ELSE 0) AS 'numthisweek',
                      SUM(CASE WHEN MONTH(clickdate) = MONTH(CURDATE()) THEN 1 ELSE 0) AS 'numthismonth',
                      SUM(CASE WHEN YEAR(clickdate) = YEAR(CURDATE()) THEN 1 ELSE 0) AS 'numthisyear'
                      FROM clicks WHERE affiliateID = '$affiliateID'");
 
// Check for errors
if(!$clicks){ mysql_error(); }
 
// Gets results from database
while($row  = mysql_fetch_array($clicks, MYSQL_ASSOC)){
 
    $clicksDay = $row['numtoday'];
    $clicksWeek = $row['numthisweek'];
    $clicksMonth = $row['numthismonth'];
    $clicksYear = $row['numthisyear'];
}   
   
This code tells me that $clicks is not a valid result resource? Thoughts?

Re: MySQL problem... "not a valid result resource"

Posted: Sat May 31, 2008 12:06 am
by nowaydown1
Looks fine to me just glancing at it. If you do a var_dump on $clicks what do you get?

Re: MySQL problem... "not a valid result resource"

Posted: Sat May 31, 2008 8:14 pm
by jkashu
The result of a var_dump of $clicks is:

bool(false)

Re: MySQL problem... "not a valid result resource"

Posted: Mon Jun 02, 2008 10:35 pm
by nowaydown1
Well, if it's tossing you false then you can bet that some kind of SQL error is probably occurring. Not sure why your mysql_error() call isn't giving you any additional information though. I would toy around with it. Try to concat a string to your mysql_error() call so you can at least see if it's entering your conditional.

Re: MySQL problem... "not a valid result resource"

Posted: Mon Jun 02, 2008 10:37 pm
by John Cartwright
mysql_error() returns the last error, it does not output it. You need to do something like,

Code: Select all

if(!$clicks){ die(mysql_error()); }

Re: MySQL problem... "not a valid result resource"

Posted: Mon Jun 02, 2008 11:13 pm
by nowaydown1
Man. Can't believe I missed that. Been working with MDB2 too much ;)