0

I have a largely PHP-based web app. that also uses - on one or two pages - JQuery and JQWidgets - both of which I am new to. For data access, I have a data-layer.php file containing all my PDO requests to the MySQL database. These all work perfectly with PHP.

In my data-layer.php file, at the end of this PDO SELECT function: getMembersAtActivity($PDOdbObject, $eventId, $actId), I have added a "json_encode($rows)" statement to translate my returned rows to JSON format, as required by JQWidgets.

All this works well. Now in my PHP/HTML page, I want to construct the nice JQWidget that uses this JSON-formatted data.

In PHP I can do a print_r to see that there is indeed an array (unnamed) of objects, returned by the getMembersAtActivity function. However, I don't know how to make a variable that contains this array in JQuery, which is necessary to populate a JQListbox with my JSON rows.

There are many, many posts here that show how to iterate through a JSON array, but this is not my problem. I first need to grab a reference to that array of objects, which is in a different PHP data file, and then iterate through the array so that I can build a list box with JQWidgets.

Thanks for any help you can provide!

1 Answer 1

1

If it's in a separate PHP file then AJAX seems like the best choice. Take a look at the documentation for the jQuery.getJSON() wrapper function. Basic usage would look something like this:

$(document).ready(function() {
    // on page load
    $.getJSON('yourpage.php', function(data) {
        // data is your array
        // use it to create your widget in here
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks very much! i was hoping to find my way thru the JSON and PDO issues before I tackle Ajax, because i'm struggling with new stuff as it is. i got hold of the JQWidgets support team too so i'm hopeful of getting the answer soon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.