Re: MySQL/PHP problem.

From: Date: Wed, 23 Jul 2003 02:20:39 +0000
Subject: Re: MySQL/PHP problem.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-156370@lists.php.net to get a copy of this message
On Tue, 22 Jul 2003 17:08:50 -0400, you wrote: >I am trying to count in mySQL the number of entries in the field "day" where day=2 or >3. > >Then I want to check just to see if that returned a value greater than 0 or not. > >I am using the code below, but having a problem, I keep getting 0 as the total > >What am i doing wrong. > > > $dbqueryshipping1 = "select *, COUNT(day) from tempuserpurchase where > day=\"2\" and day=\"3\" GROUP BY itemname"; > $resultshipping1 = mysql_db_query($dbname,$dbqueryshipping1); > if(mysql_error()!=""){echo mysql_error();} > $shipping1 = mysql_fetch_array($resultshipping1); You essentially are looking for TRUE or FALSE, right? Nothing else? a) What's the * for? b) day can never be 2 AND 3 at the same time. Boolean and/or usage is more strict than English and/or usage. Try this function x() { $query = "SELECT COUNT(*) FROM tempuserpurchase WHERE day=2 OR day=3"; [...] $a = mysql_fetch_row($r); if ($a[0]) { return (TRUE); } return (FALSE); } That should give you the core of a function that returns TRUE if there are rows in the db where day = 2 or day = 3. Expand as you wish (eg moving the magic numbers out of the sql query).

« previous php.general (#156370) next »