Re: Strange result from empty table

From: Date: Fri, 10 Dec 2004 18:52:43 +0000
Subject: Re: Strange result from empty table
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16164@lists.php.net to get a copy of this message
On Fri, 10 Dec 2004 12:39:00 -0000, George Pitcher <george.pitcher@ingenta.com> wrote: > Hi, > > I'm getting a strange result querying an empty table (MySQL 4.0). > > My code: > > $strSQLc = "select count(id) from deposit_balance where > acc_id=".vr('Acc_ID')." order by id desc"; First of all, you don't need to order a count(*) query...(I'm surprised it let you do this) > $count=$db->getOne($strSQLc); If this isn't working, try: $rec = $db->getRow($strSQLc, DB_FETCHMODE_ORDERED); $count = $rec[0]; or print_r($db->getRow($strSQLc, DB_FETCHMODE_ASSOC)); You may also want to: $count=$db->getOne($strSQLc); if (DB::isError($count)) { die($count->getMessage().' '.$count->getUserInfo()); } > echo "QUERY: $strSQLc<br>"; > echo "COUNT: $count<br>"; > > produces: > > QUERY: select count(id) from deposit_balance where acc_id=918 order by id > desc > COUNT: 1 > > It should give me a form in which I can enter details to create a record in > that table. > > If I paste the query into my MySQL editor (MySQLFront) it shows '0' in the 1 > cell returned. > > Any ideas why this is giving me such a bum result? > > Cheers > > George in Oxford > -- Justin Patrin

« previous php.pear.general (#16164) next »