Re: code not working...help?

From: Date: Thu, 07 Oct 2004 21:44:56 +0000
Subject: Re: code not working...help?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-198900@lists.php.net to get a copy of this message
On Thu, 7 Oct 2004 14:14:10 -0400, Matthew <speakez@speakezforums.com> wrote: > Hi guys im pretty new at this and cant seem to get this going.... I want the > code to query the database for the number of messages posted within the last > month this is the code i have but its not working... I might even have it > all wrong, can someone point me in the right direction? > > $lastmonth = date("YmdHis", mktime(date("H"), date("i"), > date("s"), > date("m")-1, date("d"), date("Y"))); > $countResult = db_query("SELECT count(*) AS msgCount FROM messages WHERE > uid = '". $userID ."' AND fid = '". $fid ."' AND > post_date <= '". $lastmonth > ."'"); > $countRow = db_fetch_array($countResult); > > im then using $countRow as my variable but it keeps returning a value of > zero. > Have you tried echo-ing your sql, and querying the database directly? That's where I usually start when I don't get the desired query results. You may also want to check your usage of $countRow. If it contains an array, and you're trying to access it without an index, you won't be able to retrieve the count. If that is the case, you can either access the variable using $countRow[0] or change your retrieval statement to read: list ($countRow) = db_fetch...

« previous php.general (#198900) next »