Как объединить две записи в JSON

Приведенный ниже код работает для меня, но он дает мне только один ключ для автозаполнения. Как я могу отобразить две клавиши и распечатать их. В моем случае я намерен напечатать название страны и цены в поле для предложений.

Любая помощь будет высоко оценена.

rates.php

<?php
include "includes/header.php";
?>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jqueryui/jquery-ui.min.js"></script>

<script type="text/javascript">

$(function () {

$("#dd_user_input").autocomplete({
source: "rates_config.php",
minLength: 2,
select: function (event, ui) {
var getUrl = ui.item.id;
if (getUrl != '#') {
location.href = getUrl;
}
},

html: true,

open: function (event, ui) {
$(".ui-autocomplete").css("z-index", 1000);
}
});

});
</script>
<div class="domain-prices">
<div class="row">
<div class="small-12 columns">
<h2>ForFreeCalls offers cheap calling or texting to any mobile or landline phone in the world. What country
would you like to call?</h2>

<form>
<input id="dd_user_input" class="search_form" onblur="if(this.value=='')this.value=this.defaultValue;"onfocus="if(this.value==this.defaultValue)this.value='';" placeholder="Enter a Country Name...."type="text">
</form>
</div>

</div>
</div>

<?php
?>

rates_config.php

<?php
/*====================== Database Connection Code Start Here ======================= */

define ("DB_HOST", "xxxxxxxx"); // set database host
define ("DB_USER", "xxxxxxxx"); // set database user
define ("DB_PASS", "xxxxxxxx"); // set database password
define ("DB_NAME", "xxxxxxxx"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

/*====================== Database Connection Code End Here ========================== */

// Here, we will get user input data and trim it, if any space in that user input data
$user_input = trim($_REQUEST['term']);

// Define two array, one is to store output data and other is for display
$display_json = array();
$json_arr = array();$user_input = preg_replace('/s+/', ' ', $user_input);

$query = 'SELECT vr.CountryName,vr.SellingRate FROM voip_routes as vr WHERE vr.CountryName LIKE "%' . $user_input . '%"';

$recSql = mysql_query($query, $link);
if (mysql_num_rows($recSql) > 0) {
while ($recResult = mysql_fetch_assoc($recSql)) {
$json_arr["name"] = $recResult['CountryName'];
$json_arr["value"] = $recResult['SellingRate'];
array_push($display_json, $json_arr);
}
} else {
// $json_arr["Id"] = "#";
$json_arr["name"] = "";
$json_arr["value"] = "No Result Found !";
array_push($display_json, $json_arr);
}

// json_encode($recSql);// json_encode($display_json);
$jsonWrite = json_encode($display_json); //encode that search data
print $jsonWrite;
?>

1

Решение

Вы можете сделать это,
$json_arr["name"] = $recResult['CountryName']." ".$recResult['SellingRate'];

0

Другие решения

Возможно, вы ищете что-то вроде этого:

$json_arr["name"] = $recResult['CountryName'].' '.$recResult['SellingRate'];

Или может быть эта комбинация:

$json_arr["name"] = $recResult['CountryName'].' '.$recResult['SellingRate'];
$json_arr["value"] = $recResult['CountryName'].' '.$recResult['SellingRate'];
0