RE: [PHP] syntax question

From: Date: Tue, 07 Feb 2012 16:16:15 +0000
Subject: RE: [PHP] syntax question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-316527@lists.php.net to get a copy of this message
> -----Original Message----- > From: marco@behnke.biz [mailto:marco@behnke.biz] > Sent: Tuesday, February 07, 2012 10:47 AM > To: php-general@lists.php.net; admin@buskirkgraphics.com > Subject: Re: [PHP] syntax question > > > > admin@buskirkgraphics.com hat am 7. Februar 2012 um 15:11 geschrieben: > > > 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 > > table2.name from > > table1 ,table2 WHERE > > > > table2.user_id=table1.seller_id > > AND > IF(table2.name¢, > ^�MT}\„`¾¹O='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.name FROM > > table1 ,table2 WHERE > > > > table2.user_id=table1.seller_id > > AND > > IF(table2.name='juice','No > > Juice for YOU', > > table2.name=table2.name) > > GROUP BY > table1.ID > > LIMIT 1"; > > > This is a nice query but I am not sure if I understand what you want to > do? > Maybe we could start with your error message and a table structure :-) > That > would be handy. > > You wanna get all users that have at least on sell? But only once? > > Maybe something like that? > > SELECT table2.name > FROM > table2, > (SELECT seller_id FROM table1 GROUP BY seller_id) as table1 > WHERE > table2.user_id = table1.seller_id > AND IF(table2.name = 'juice','No Juice for YOU', table2.name = > table2.name) > ; > > > > > Marco Behnke > Dipl. Informatiker (FH), SAE Audio Engineer Diploma > Zend Certified Engineer PHP 5.3 > > Tel.: 0174 / 9722336 > e-Mail: marco@behnke.biz > > Softwaretechnik Behnke > Heinrich-Heine-Str. 7D > 21218 Seevetal > > http://www.behnke.biz Marco, Thank you but the whole issue stemed from the 2nd table in the FROM. I just did an inner join using the If statement and it resolved the whole issue. Maybe it was just a coffee thing because 2 cups later I seen it very clearly :) Thanks so much.

« previous php.general (#316527) next »