Sebastian wrote:

Michael Stassen wrote:
<snip>
So, why spend days trying to come up with complicated, ugly sql when it can be done in 5 minutes with simple, easy-to-read php?

Michael

i only posted snip of the query.. it is much larger and complex than just a SELECT. i am going MATCH, AGAINST, LEFT JOINS, and other operations for a search engine. doing it in the app (php in my case)

Well, that's the first problem. When you ask about a simplified version of your problem, you run the risk of getting answers which apply to your simplified problem rather than your real problem. Unless you are certain that answers to the simplified version will be generally applicable (apparently not the case here), you should post your real query.

would mean i would end up with a huge block of SQL code which would seem more ugly IMO..

I don't see it. Your basic query is longer and more complicated than you've shown, but you still have the same problem. You need one query if $cat is set, 3 unioned queries if $cat is not.

.. on top of that i am paginating the results which would mean i would have to duplicate the code you posted above since there would be no point in selecting many other columns just to get a row count for the pagination part so i couldn't re-use the IF statement output as shown above.

But don't you have this problem anyway? You need a pagination query and a full query, each of which is one version of the long, complicated query you describe, with "MATCH, AGAINST, LEFT JOINS, and other operations", or the other. If the only difference is the list of columns selected, it shouldn't be too hard to put that in a variable and reuse the if..else.

Of course, ugliness, like beauty, is in the eye of the beholder. Perhaps you'll prefer the one-statement-in-sql version I sent in my first reply to Mathias' suggestions. It's just a matter of adding 2 conditions to each WHERE clause in the UNION, so I think it will meet your specs, even for your real query.

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to