我的查询是
SELECT *
FROM `wp_patient_bill`
WHERE `bill_code` !=''
AND `is_billed` = 'Y'
AND `charged` = 'N'
AND `id` IN (97,419,631,632,633,422,635,421,35,799,60,423)
我希望记录数组按照我的列表排序,即ID
'97,419,631,632,633,422,635,421,35,799,60,423'
。我正在使用PHP。请建议我优化的方法。
答案 0 :(得分:5)
这是另一种解决方案:
SELECT *
FROM `wp_patient_bill`
WHERE `bill_code` !=''
AND `is_billed` = 'Y'
AND `charged` = 'N'
AND `id` IN (97,419,631,632,633,422,635,421,35,799,60,423)
ORDER BY FIELD(`id`,97,419,631,632,633,422,635,421,35,799,60,423)
答案 1 :(得分:1)
假设您的ID列表在数组中
$data["{$row['id']}"] = $row;
答案 2 :(得分:0)
在查询末尾添加“ORDER BY ID”语句。