I'm making search in BD MySQL, but I can't get result I need. This is php code
$mass = json_decode(file_get_contents('php://input'), true);
foreach ($mass as $mass_item) {
if($mass_item['name']=="Наименование" && isset($mass_item['val']))
$exp=$mass_item['val'];
}
$query = "SELECT * FROM Companies WHERE LOWER(name) RLIKE
LOWER('".$exp."') ";
$result = mysql_query($query) or die();
while($row=mysql_fetch_array($result)){
echo json_encode($row);
}
This is an angular code `
$http.post("search.php", value).then(function success (response) {
console.log(response);
console.log(response.data);
},function error (response){
console.log(response.data);
}
);`
As a result in console I see empty row "". But if I add one more echo before or in while
, like echo $row['name']
in console will be all expected result. I need to get query in json format to work with it. Please help.
you are trying to echo every row, change php code to something like that:
$resultJson = [];
while($row=mysql_fetch_array($result)){
$resultJson[] = $row;
}
echo json_encode($resultJson);
die;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.