我知道这个问题之前已经问过多次了,但是我无法找到我的错误所在。
问题:当使用mysql_num_rows时,它返回错误的结果。
$sql = "SELECT * FROM $topic WHERE $names LIKE '%$q%'";
但是,如果我将 $sql 替换为以下任何一个,它都会返回 true。
$sql = "SELECT * FROM $topic WHERE $names LIKE '%j%'";
$sql = "SELECT * FROM $topic WHERE $names ='Jack'";
$sql = "SELECT * FROM $topic WHERE $names = '$q' ";
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%'";
$row['ID']的var_dump将会显示
"SELECT * FROM Cust_Reg WHERE fName LIKE '%j%'" string(4) "NjA="
string(4) "NjE=" string(4) "NjQ=" string(4) "NjY=" string(4) "ODI="
如果您能纠正我错误的地方,我将不胜感激。
$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['search'] )
сђѓтюеТѓетйЊтЅЇуџёТхІУ»Ћтю║ТЎ»СИГ№╝їт«Ѓт«ъжЎЁтїЁтљФС╗ђС╣ѕ№╝Ъ - nobody