MySql搜索查询无法返回包含%20的行
我的数据库查询有问题。当我尝试提取先前将空格转换为%20的行时,查询返回null。我已经测试了其他行,这些行运行良好,为什么会出现此问题?我是否需要从每行手动删除%20才能使其正常工作 谢谢MySql搜索查询无法返回包含%20的行,mysql,database,operators,query-string,Mysql,Database,Operators,Query String,我的数据库查询有问题。当我尝试提取先前将空格转换为%20的行时,查询返回null。我已经测试了其他行,这些行运行良好,为什么会出现此问题?我是否需要从每行手动删除%20才能使其正常工作 谢谢 <?php include_once 'includes/db_connect.php'; $query = "SELECT * FROM USERS WHERE LIKES= '$_GET[imgname]' "; //Creating resonse json array, with ano
<?php
include_once 'includes/db_connect.php';
$query = "SELECT * FROM USERS WHERE LIKES= '$_GET[imgname]' ";
//Creating resonse json array, with another array inside
$jsonResponse = array( "info" =>array() );
if($result = mysqli_query($mysqli, $query)) {
while($row = mysqli_fetch_assoc($result)){
$jsonRow = array(
'names' => $row['USERNAME'],
'userIds' => $row['USERID']
);
//adding the $jsonRow array to the end of the "users" array as key/value
array_push($jsonResponse["info"], $jsonRow);
}
}
//encoding to json for the app
echo json_encode($jsonResponse);
?>
将SQL查询更改为:
$query = "SELECT * FROM USERS WHERE LIKES= '".rawurlencode($_GET[imgname])."' ";
LIKES
列对图像路径进行了编码(空间转换为%20
)。因此,$\u GET[imgname]
应该进行编码以匹配数据库记录。请发布您的表结构,以及5-10行示例数据和预期结果。如果没有这两个问题,就很难确定你到底在问什么。@McAdam331-请查看我更新的问题。感谢您的建议,但不幸的是搜索查询仍然返回null。当我回显我得到的结果时:Crush%20Coffee%20House%2faselnut_late.jpg-第二个空格变形为:%2F,而忽略了“/”我猜它是一个保留符号。我使用了:$strnew=str_replace(“%2F”、“/”、$str);为了解决这个问题。谢谢