我的数据库查询有问题。当我尝试先将空格转换为%20的行时,查询返回null。我测试了其他行正常工作,为什么会出现这个问题?我是否需要从每一行手动删除%20以使其正常工作?
谢谢!
<?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);
?>
答案 0 :(得分:0)
将您的SQL查询更改为:
$query = "SELECT * FROM USERS WHERE LIKES= '".rawurlencode($_GET[imgname])."' ";
LIKES
列已对图像路径进行编码(空间转换为%20
)。因此,$_GET[imgname]
应编码为与数据库记录匹配。