私はdbから同じ名前を持つことができるユーザーのリストを取得する必要があります。私は問題を私の質問の結果をjsonに変換している。複数のjsonをPHP経由で返す
私が1つの結果しか取得しようとしなかった場合、コードは機能しますが、LIKE
の使用が開始されてから失敗しました。
PHPコード:
<?php
$q = $_POST['q'];
require('connect.php');
$i = 0;
$sql="SELECT `_nome`, `_endereco`, `_telefone`, `_imgstring`, `_dtAcesso`, `_descricao`, `_fkIdUser` FROM `tbvisitantes` WHERE _nome LIKE CONCAT ('%',?,'%')";
$stmt= $conn->prepare($sql);
$stmt->bind_param('s', $q);
if ($stmt){
$stmt->execute();
$stmt->bind_result($rName, $rEndereco, $rTelefone, $rImgString, $rDtAcesso, $rDescricao, $rFkIdUser);
while ($row = $stmt->fetch_array()){
$json_output = array('name' => $rName, 'address' => $rEndereco, 'tel' => $rTelefone, 'imgString' => $rImgString, 'dtAcesso' => $rDtAcesso, 'descricao' => $rDescricao, 'fkIdUser' => $rFkIdUser);
echo json_encode($json_output);
}
$stmt->close();
}
mysqli_close($conn);
?>
結果を受信するスクリプト:
$.ajax({
url: 'getuser.php',
type: 'POST',
data: {q: str},
success: function(jsonString){
$vIndex = '<input class="vInput"></input>';
$($cadContent).appendTo('#cadContent');
var json = $.parseJSON(jsonString);
var jsonLenght = Object.keys(jsonString).length;
$.each(json, function(index, el) {
$($vIndex).attr('id', index).val(el).appendTo('#txtHint');
});
}
})
.done(function() {
console.log("success");
})
.fail(function(xhr) {
alert("An error ocurred:" + xhr.status + xhr.statusText);
console.log('failed');
})
.always(function() {
console.log("complete");
});
}
私は私の問題は私のJSONの構造にすることによって可能性があることと思いますが、どのように私は今ありません修理する。