I have developed following code which getting data from db.
//get number of stores for zip code
$numberofstores = $resultstore = mysqli_query($conn, "SELECT store,address FROM geoinfo WHERE zipcode = '$search_text'");
//get values from db
$addressArray = Array();
$storeArray = Array();
while ($row = mysqli_fetch_array($resultstore, MYSQL_ASSOC)) {
$storeArray[] = $row['store'];
$addressArray[] = $row['address'];
}
//return data to the client
echo json_encode($addressArray);
echo json_encode($storeArray);
$total = mysqli_num_rows($resultstore);
if(mysqli_num_rows($resultstore) != 0) {
echo "".$total." store/s found within this area";
Here is my ajax call ,
$(function () {
$('#form_geocode').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'controller.php',
dataType: 'text',
data: $('#form_geocode').serialize(),
success: function (data) {
for (var x = 0; x < data.length; x++) {
$("#location_results").html(data[x]+"<br>");
}
}
});
});
});
On success output is,
["226 N LARCHMONT BLVD, LOS ANGELES, CA","670 S WERN AVE, LOS ANGELES, CA","3201 W 6TH ST, LOS ANGELES, CA"]["RITE AID PHARMACY","RALPHS","WALGREENS?"]3 store/s found within this area
My question is how can I extract 2 arrays into 2 arrays in js and store text separate variable.Please help.