我知道這個問題以前已經被問過好幾次了,但是我無法找到我的方式的錯誤。MySQL/PHP like百分號不起作用
問題:mysql_num_rows是返回false結果時
$sql = "SELECT * FROM $topic WHERE $names LIKE '%$q%'";
但是,如果我取代以下任何$ sql中,它將返回true。的var_dump
string(8) "Cust_Reg" string(5) "fName" string(2) "j "
resource(8) of type (mysql result)
string(46) "SELECT * FROM Cust_Reg WHERE fName LIKE '%j %'"
的
$sql = "SELECT * FROM $topic WHERE $names LIKE '%j%'";
$sql = "SELECT * FROM $topic WHERE $names ='Jack'";
$sql = "SELECT * FROM $topic WHERE $names = '$q' ";
結果如果我改變$ SQL = 「SELECT * FROM $話題,其中$名稱LIKE '引用%j%'」;
的var_dump爲$行[ 'ID']將顯示
"SELECT * FROM Cust_Reg WHERE fName LIKE '%j%'" string(4) "NjA="
string(4) "NjE=" string(4) "NjQ=" string(4) "NjY=" string(4) "ODI="
如果你能糾正我在我的方式錯誤,我會apprecaite它。
$q = mysql_real_escape_string($_GET['search']);
$q = strtolower($q);
$topic = mysql_real_escape_string($_GET['test']);
$names = mysql_real_escape_string($_GET['name']);
// SELECT * from Account_Reg where Account_Name LIKE '%$q%'
$table = "<table style='width:400px; padding:10; display:block;'><tbody>
<tr><td>ID</td><td>Account</td><td>First Name</td><td>Email</td></tr>";
$sql = "SELECT * FROM $topic WHERE $names LIKE '%{$q}%'";
$result = mysql_query($sql) or die (mysql_error());
var_dump($topic);
var_dump($names);
var_dump($q);
var_dump($result);
var_dump($sql);
if(is_resource($result) && mysql_num_rows($result) > 0){
while($row = mysql_fetch_array($result)) {
$table .= "<tr><td>".$row['ID']."</td>";
$cryt = base64_encode($row['ID']);
$row['ID'] = htmlspecialchars($cryt);
$link = "profile.cust.update.php?id=". urlencode($row['ID']);
$link = htmlentities($link);
if($names == "fName"){
$name = $row['fName'];
}elseif($names == "Account_Name"){
$name = $row['Account_Name'];
$row['email_add'] = "";
}
$table .="<td></td><td><a href='" .$link ."'</a>" .$name."</td><td>".$row['email_add']."</td></a> </tr>";
}$table .="</tbody</table";
}else{$table = "No row is selected"; }
'的var_dump($ _GET [ '搜索'])'。它在你當前的測試場景中實際上包含了什麼? – nobody