RE: [PHP] syntax question

From: Date: Tue, 07 Feb 2012 14:27:56 +0000
Subject: RE: [PHP] syntax question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-316524@lists.php.net to get a copy of this message
> -----Original Message----- > From: Louis Huppenbauer [mailto:louis.huppenbauer@gmail.com] > Sent: Tuesday, February 07, 2012 9:24 AM > To: admin@buskirkgraphics.com > Cc: php-general@lists.php.net > Subject: Re: [PHP] syntax question > > Generally... Wouldn't grouping by an id (which is normally unique) have > no > real benefit... Except some strange behaviour? > > Just to clarify: Why aren't you sticking to the LIMIT 1? > > 2012/2/7 <admin@buskirkgraphics.com> > > > I have been struggling with this issue for an hour and honestly I am > not > > sure why. > > > > I consider myself to be pretty savvy with MySQL but I am running into > an > > syntax error that is just flat out eluding me. > > > > > > > > $query = "SELECT ÌÀE� > > c€qG@À]øtable2.name from > > table1 ,table2 WHERE > > > > table2.user_id=table1.R€ > > !µ– NõE¾}¼Î}àseller_id AND > > IF(table2.name='juice','No > > Juice for YOU', > > table2.name=table2.name) > > LIMIT 1"; > > > > This query works!! > > > > > > > > But If I try to add a GROUP BY to the query, complete failure. > > > > $query = "SELECT table2.nameDÓ; > > ºò"ù€G×i» FROM table1 ,table2 > > WHERE > > table2.user_idÅ¡ª > > Lüu÷üðÈsžk¸q=table1.seller_id AND > IF(table2. >name='juice','No > > Juice for YOU', > > table2.name=table2.name) > > GROUP BY > table1.ID > > LIMIT 1"; > > > > > > > > The main goal here is to get only 1 return but MySQL is returning the > same > > row 2 times. > > > > Before I beat my head in anymore I will toss this out to you guys and > beat > > myself up later for not drinking enough coffee or something . > > > > There is no real reason to have a LIMIT It was just yet another attempt to limit the results during the testing. After reading my post back I see an error in the IF statement but not the resolution to the issue. The IF should read IF(table2.name='juice',table2.name=table1.code, table2.name=table1.ref)

« previous php.general (#316524) next »