Joomla PHP MySQL Query to use MySQL IF function -
so have joomla site , in joomla documentation can't find mysql's if, else function within query.
the part of query need if statement in mysql here.
$query->where($db->quotename('container').' != 1');
it should doing :
$query->where('if '.$db->quotename('server_number').' != '.$number.' '$query->where($db->quotename('container').' != 1');' end');
if $number input not match server_number column data add statement mysql query.
full mysql query :
select a.*,ext.media_type database_hwdms_processes left join database_hwdms_media media on media.id = a.media_id left join database_hwdms_ext ext on ext.id = media.ext_id (a.status = 1 || a.status = 3) , a.attempts < 5 , `container` != 1 , server = 1 order a.media_id asc
want add "if server_number != 1 container != 1 end" mean replacing "and container
!= 1"
i figured out better way resolve problem using mysql's
or ||
function
so fixed code became :
php :
$query->where('('.$db->quotename('server_number').' = '.$number.' || '.$db->quotename('container').' != 1 )');
in plain mysql text :
select a.*,ext.media_type database_hwdms_processes left join database_hwdms_media media on media.id = a.media_id left join database_hwdms_ext ext on ext.id = media.ext_id (a.status = 1 || a.status = 3) , a.attempts < 5 , ( `server_number` = 1 || `container` != 1 )and server = 1 order a.media_id asc
Comments
Post a Comment