create a mysql query with using php arrays -
i have , arrray below
$titles=array("dr.","ms.","mr.");
after foreach loop, create query below
select * `table` title = 'dr.' or title = 'ms.' or title = 'mr.' ) group sentences
output start
mr. ms. mr. dr.
i want put dr. first ms. mr. in order inside of array()
as long input sanitized, can use implode
prepare statement.
$stmt = 'select * `table` '; $stmt .= "where title = '" . implode("' or title = '", $titles) . "'";
result
select * `table` title = 'dr.' or title = 'ms.' or title = 'mr.'
you can alternatively use in
:
$stmt = 'select * `table` '; $stmt .= "where title in ('" . implode("', '", $titles) . "')";
result
select * `table` title in ('dr.', 'ms.', 'mr.')
you need fix group by
; you're not using correctly.
if want sort order of titles, can try:
order case when title = 'dr' 1 when title = 'ms.' 2 when title = 'mr.' 3 else 4 end
Comments
Post a Comment