此代碼在通過where命令添加命令時不起作用。ORDER BY和WHERE mysql和php
$sel = "SELECT * FROM items ORDER BY 'item_no' WHERE mainitem_id=".$_GET['cate_id'] ;
此代碼在通過where命令添加命令時不起作用。ORDER BY和WHERE mysql和php
$sel = "SELECT * FROM items ORDER BY 'item_no' WHERE mainitem_id=".$_GET['cate_id'] ;
使用ORDER BY你查詢的末尾:
$sel = "SELECT * FROM items WHERE mainitem_id='".addslashes($_GET['cate_id'])."' ORDER BY item_no;
$sel = "SELECT * FROM items
WHERE mainitem_id='".$_GET['cate_id']."'
ORDER BY item_no";
但是請注意,你的代碼是vurnerable到SQL注入。請解決這個問題。見here
用途:
$sel = "SELECT * FROM items WHERE mainitem_id=".mysqli_real_escape_string($conn, $_GET['cate_id'])."ORDER BY 'item_no'" ;
mysqli_real_escape_string()
會保護你免受SQL注入。
GET變量更容易爲sql injections.So做檢查http://php.net/manual/en/security.database.sql-injection.php
$cate_id = mysql_real_escape_string($_GET['cate_id']); //or any proper similar function (mysqli recommended)
$sel = "SELECT * FROM items WHERE mainitem_id='$cate_id' ORDER BY 'item_no'";
對不起仍然無法正常工作和我建立由MySQL的所有頁面 – user2424747