jQWidgets Forums
jQuery UI Widgets › Forums › Lists › ComboBox › Combobox json $.getJSON php issue
This topic contains 0 replies, has 1 voice, and was last updated by andymager 12 years, 1 month ago.
-
Author
-
I would like to have a custom rendering with json from php . I could use your example “Custom Rendering” but the problem is that. How can i use php data with json instead of array so i can use it in the listbox or combobox ?
i red about $.getJSON passing the array as localdata to dataadapter .
Can you help me with the code ?This is my code:
// prepare the data
var source =
{
datatype: “json”,
datafields: [
{ name: ‘LAST_NAME’},
{ name: ‘FIRST_NAME’},
{ name: ‘ID_PERSON’},
{ name: ‘MOBILE_PHONE’},
{ name: ‘PLATE’},
],
url: ‘listboxdata.php’
};var data = [];
var dataAdapter = new $.jqx.dataAdapter(source);
$.each(source, function(i, obj) {
data[“LAST_NAME”]=obj.LAST_NAME;
data[“FIRST_NAME”]=obj.FIRST_NAME;
data[“ID_PERSON”]=obj.ID_PERSON;
data[“MOBILE_PHONE”]=obj.MOBILE_PHONE;
data[“PLATE”]=obj.PLATE;
});var dataAdapter = new $.jqx.dataAdapter(source);
$(‘#combobox’).jqxComboBox({ selectedIndex: 0, theme: theme, source: dataAdapter, displayMember: “firstname”, valueMember: “notes”, itemHeight: 70, height: 25, width: 270,
renderer: function (index, label, value) {
var datarecord = data[index];
var imgurl = ‘../../images/’ + label.toLowerCase() + ‘.png’;
var img = ”;
var table = ” + img + ” + datarecord.FIRST_NAME+ ” ” + datarecord.LAST_NAME + ” + datarecord.PLATE + ”;
return table;
}
});//—————————————————————————————
// PHP FILE#Include the connect.php file
include(‘connect.php’);
#Connect to the database
//connection String
$connect = mysql_connect($hostname, $username, $password)
or die(‘Could not connect: ‘ . mysql_error());
//Select The database
$bool = mysql_select_db($database, $connect);
if ($bool === False){
print “can’t find $database”;
}
// get data and store in a json array
$query = “SELECT * FROM list”;
// SELECT COMMAND
$result = mysql_query($query) or die(“SQL Error 1: ” . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$list[] = array(
‘LAST_NAME’ => $row[”LAST_NAME’],
‘FIRST_NAME’ => $row[‘FIRST_NAME’],
‘ID_PERSON’ => $row[‘ID_PERSON’],
‘MOBILE_PHONE’ => $row[‘MOBILE_PHONE’],
‘PLATE’ => $row[‘PLATE’],
);
}
echo json_encode($list);Thank you.
-
AuthorPosts
You must be logged in to reply to this topic.