Welcome to Array Web Development's Dedicated Blog Site at MarketingPortland.com.
FROM THE ARCHIVES: Get Them to Kick the Desk     MARKETING SNIPPETS: The best revenge is massive success. -Frank Sinatra     GRANNYISM #72: Absence makes the heart grow fonder.~via SweetLeaf

Quick tip, based on a little trouble I was having earlier... Say you want JDatabase to do a query that returns a recordset based on two rules:

  1. records with an id of 123 in the DB
  2. another where clause that has an OR operator in it... say that a column `val2` must either be 0 or between 234 and 345

Ok, if you're like me, you probably code this using two normal WHERE clauses, like so...

  2.      $query->where(' `id` = 123 ');
  3.      $query->where(' `val2` = 0 or ( `val2` > 234 and `val2` < 345 )' );

Seems legit, right? However, Joomla would render the query as:

  2.      SELECT * FROM #__table WHERE `id` = 123 AND `val2` = 0 or ( `val2` > 234 and `val2` < 345 )

See the problem? Where Joomla sews these two where clauses together, it loses the logic of your distinct WHERE statements. As written, that query would not return the results you want. It would instead only return:

  1. items with 123 as the id and also a val2 value of 0, and
  2. items with any id but val2 values between the values specified.

The fix is to put the 2nd entire WHERE in parens of its own, as in:

  2.      $query->where(' `id` = 123 ');
  3.      $query->where('( `val2` = 0 or ( `val2` > 234 and `val2` < 345 ))' );

.... which renders:

  2.      SELECT * FROM #__table WHERE `id` = 123 AND (`val2` = 0 or ( `val2` > 234 and `val2` < 345))

And that would be the correct result list. :-)

Useful Connections!

Get Help with Your Company's Web Site

Thanks for reading Array Web Development's "Marketing Portland" blog. Need help with a web project? Click here to contact us today and tell us about it.

On Facebook?

Please visit / like our Facebook page.

On Medium.com?

Follow Jim on Medium to read more web, business, and marketing articles.

Get Free Web Tips and Marketing Advice

We're actually migrating this blog to our new online publication, "Web Designer / Developer Magazine". Pop your email below and you'll get our newsletter (about once/month) with our latest writings on web development, SEO, technology, and more! Zero spam, just great advice and info.

Professional web development, Joomla! development, traditional marketing, and business development services.
Call (503) 902-HTML now to discuss your project!