dimanche 12 juin 2016

Joomla PHP MySQL Query to use MySQL IF function

So i have a Joomla site and in the joomla documentation I can't find anything to do with MySQL's IF, ELSE function within a query.

The part of the query i need a if statement in MySQL is here.

$query->where($db->quoteName('container').' != 1');

It should be doing something like this :

$query->where('IF '.$db->quoteName('server_number').' != '.$number.' THEN '$query->where($db->quoteName('container').' != 1');' END');

If the $number input does not match with the server_number column data then to add a where statement to the mysql query.

Full MySQL Query :

SELECT a.*,ext.media_type
FROM database_hwdms_processes AS a
LEFT JOIN database_hwdms_media AS media ON media.id = a.media_id
LEFT JOIN database_hwdms_ext AS ext ON ext.id = media.ext_id
WHERE (a.status = 1 || a.status = 3) AND a.attempts < 5 AND `container` != 1 AND
 server = 1
ORDER BY a.media_id ASC

Want to add a IF server_number != 1 THEN WHERE container != 1 END

Aucun commentaire:

Enregistrer un commentaire