Can you execute multiple SELECT statements on a MySQL DB?
How do I execute a query like this using PHP:
SELECT [name] FROM [items] WHERE [ID]=1, [ID]=2, [ID]=3
and have MySQL return me all 3开发者_运维技巧 rows?
ID name
-- ----
1 John
2 Jane
3 Jack
Use:
SELECT name
FROM ITEMS
WHERE id IN (1, 2, 3)
$result = mysql_query("SELECT name FROM items WHERE id IN (1, 2, 3)");
while($row = mysql_fetch_array($result)) {
echo $row['name'];
echo "<br />";
}
select [id], [name] from [items] where [id] in (1,2,3) order by [id]
精彩评论