我正在学习如何。。但是失败了。。。。当我运行这个查询时,我会得到输入的产品类型的所有产品。
$productchk = "SELECT products"
. " from products"
. " WHERE active = '0' and product_type = '" . [v_product_type] . "'";
但我需要添加以下内容:
order by product Limit 1
我已经尝试过了。"我不断收到语法错误。
我原以为在语句末尾的".";
之前添加它会起作用,但它不起作用。。
有什么想法吗?
此外。。你会在网上查找什么来学习如何创建这样的语句?
最后一个'关闭product_type的值,因此如果在其中插入内容,它将被解释为该值的一部分。追加在"'"之后,但在结束的";"之前。
有效:
$productchk = "SELECT products"
. " from products"
. " WHERE active = '0' and product_type = '" . [v_product_type] . "'"
. " order by product Limit 1";
此外,请使用存储过程和准备好的语句!是1。更快,2。更安全,3。较少逃逸
$productchk = "SELECT products"
. " FROM products"
. " WHERE active = '0' AND product_type = '" . $v_product_type . "'"
. " ORDER BY product LIMIT 1";