jQWidgets Forums

jQuery UI Widgets Forums Lists ListBox Rendering with PHP and JSON , how to

This topic contains 1 reply, has 1 voice, and was last updated by  andymager 12 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Rendering with PHP and JSON , how to #18964

    andymager
    Member

    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;
    });

    $(‘#listbox’).jqxListBox(
    {
    source: dataAdapter,
    theme: ‘darkblue’,
    width: ’100′,
    height: ’100%’,
    selectedIndex: 0,
    displayMember: ‘LAST_NAME’,
    valueMember: ‘FIRST_NAME’,
    itemHeight: 70,
    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

    $row[”LAST_NAME’],
    ‘FIRST_NAME’ => $row[‘FIRST_NAME’],
    ‘ID_PERSON’ => $row[‘ID_PERSON’],
    ‘MOBILE_PHONE’ => $row[‘MOBILE_PHONE’],
    ‘PLATE’ => $row[‘PLATE’],
    );
    }
    echo json_encode($enquiry);
    ?>

    Thanks in advance.

    Rendering with PHP and JSON , how to #18967

    andymager
    Member

    #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);

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.