From php to list via regex

51 views
Skip to first unread message

Mathias

unread,
Jun 4, 2014, 9:48:07 AM6/4/14
to comman...@googlegroups.com
Hello,

for an internal project, I'd like to fill a list from a php database. Since I'm not an expert in php I've got someone who does the php for me.
When I enter the URL in my browser I do see a list, which I'd like to put into a list in iViewer:
The webpage give me something like:

13.06.2014:14.06.2014

which are possible dates, divided by an ":"

How can I capture these into a list with regex.

When I test it in the regex tester with 

(.*):

I only got the first date. 
When I do

(.*):(.*): 

I do got both (in different groups), but there are databases, where the number of the dates vary.

How do I "repeat" the capturing, or is it done because it is a list where I'm capturing to?

Thanks for your help

Mathias



Terence

unread,
Jun 4, 2014, 10:05:55 AM6/4/14
to comman...@googlegroups.com
You can split the incoming data by setting the End of Message (EOM) in your System properties as :
This will split your data every time a : is encountered.

Jarrod Bell

unread,
Jun 4, 2014, 11:12:04 AM6/4/14
to comman...@googlegroups.com
METHOD 1: Using NO scripting (suits your simple data format)
In your feedback properties, assign the "list join" to the top right, matching your list join number where you want the data to append to.
Then above your capture groups, add an "on match" item, and set the target to list join, again the join of your list, then set the value to c
This will cause it to create a "content" subpage in the list.
Then in your capture groups, set the data type to serial, and the join to match the serial joins of the dates used in your list subpages.


METHOD 2: Using JavaScript - recommend this only if you need to use more advanced data later on,
Ask your PHP developer to use json_encode on the date array, and simply print the string result to screen.
The result you see in your browser would be something like this:
[["date 1","date 2"],["date 3","date 4"]]

Then in iViewer, create a script that does something along the lines of:

function requestDates() {
    CF.request("YOUR URL HERE", function(status, headers, body) {
        if (status == "200") {
            var myData = JSON.parse(body);
            CF.listRemove("l1"); // Clear your list of any previous data, change l1 to match your list join number, prefixed with lowercase L
            // Loop through your data, assigning the info to joins to use in your list
            var newListData = [];
            for (var item in myData) {
                var dateLine = myData[item];
                newListData.push({s1: dateLine[0], s2: dateLine[1]}); // Change s1 and s2 to match the serial joins of the items in your list for date 1 and date 2.
            }
            // Add the data to the list
            CF.listAdd("l1", newListData); // Again change l1 to match your list join   
        } else {
            CF.log("SOMETHING WENT WRONG!");
        }
    });
}

Save that script into a file called "main.js" then add the script to your project via the script manager.

Now create a button to call the data, and in the button properties under "javascript" property, add this:
requestDates();

Depending on how the data is returned via the script, this will change a bit, but if you need help, simply show us how the JSON data looks.
By returning JSON data from the PHP script, it makes it much easier to process in our JavaScript engine.

Regards,

Jarrod Bell
CommandFusion
www.commandfusion.com


--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages