我想显示从表中选择的查询
<?php
$where = "";
if(isset($_GET['category']))
{
$catid = $_GET['category'];
$where = " WHERE product.categoryid = $catid";
}
因此是$where
函数,用于获取类别
$sql = "SELECT category.*,
category.category_id , items.id AS itemID,items.asset_tag,items.name,
items.brand,items.status,
items.quantity,items.category_id,
items.color,items.texture,items.photo,items.date,
items.fetch_item FROM items LEFT JOIN category ON
category.category_id=items.category_id
WHERE items.status = 'Available' AND items.fetch_item = '0' $where";
?>
答案 0 :(得分:2)
看起来您犯了个小错误,因为在“默认”查询中您已经有WHERE
语句,因此在if中您应该使用AND
或OR
而不是{{1 }}:
WHERE
此外,您可以使用sprintf()函数使注入其他$where = "";
if(isset($_GET['category']))
{
$catid=$_GET['category'];
$where = " AND product.categoryid = $catid";
}
条件更加优雅。看一个例子:
WHERE