Parsing Tablepress table with PHP
-
Hi
I’m trying to parse a Tablepress table using my own Javascript to display in IOS and treating the post_content as JSON, but I cannot get the table to read correctly as JSON data.
The data as stored does not look or function like proper JSON data. Even testing the data using export to JSON doesn’t seem to create proper formatted JSON data.
Data is stored as Column Name, Column Name etc followed by data, data as opposed to Column Name:Data, Column Name:Data
Eg
“data”:[[“Pos”,”Team”,”P”,”W”,”L”,”D”,”BP”,”LP”,”Pts”,””],[“”,””,””,””,””,””,””,””,””,””],[“<font color=’red’><b>C<\/b><\/font>”,”<b>Rattlers<\/b>”,”<b>22<\/b>”,”<b>17<\/b>”,”<b>5<\/b>”,”<b>0<\/b>”,”<b>170<\/b>”,”<b>153<\/b>”,”<b>323<\/b>”,””],[“<font color=’red’><b>R\/U<\/b><\/font>”,”Team A”,”22″,”17″,”5″,”0″,”170″,”147″,”317″,””],[“3″,”Team B”,”22″,”15″,”7″,”0″,”150″,”137″,”287″,””],[“4″,”Team C”,”22″,”10″,”9″,”3″,”115″,”120″,”235″,””],[“5″,”Team D”,”22″,”12″,”10″,”0″,”120″,”105″,”225″,””],[“6″,”Team E”,”22″,”10″,”12″,”0″,”100″,”121″,”221″,””],[“7″,”Team F”,”22″,”10″,”11″,”1″,”105″,”113″,”218″,””],[“8″,”Team G”,”22″,”10″,”10″,”2″,”110″,”101″,”211″,””],[“9″,”Team H”,”22″,”11″,”11″,”0″,”110″,”94″,”204″,””],[“10″,”Team I”,”22″,”7″,”15″,”0″,”70″,”89″,”159″,””],[“11″,”Team J”,”22″,”5″,”17″,”0″,”50″,”69″,”119″,””],[“12″,”Team K”,”22″,”5″,”17″,”0″,”50″,”61″,”111″,””]]
I want to read the column names and data as posted in the post_content to redisplay in an IOS application.
Using the following Javascript does not return any data:
jsonArray = $.parseJSON(xhr.responseText);
var html = “<table align=’center’ width=’99%’ cellpadding=’4′ border=’0′ style=’margin-left: 2px;font-size: 10pt; border-collapse: collapse;’><thead><tr><td>Pos</td><td>Team</td><td>P</td><td>W</td><td>L</td><td>D</td><td>BP</td><td>LP</td><td>Pts</td></tr></thead><tbody>”;
for(i=0; i < jsonArray.length; i++)
{
pos = jsonArray[i].Pos;
team = jsonArray[i].Team;
p = jsonArray[i].P;
w = jsonArray[i].W;
L = jsonArray[i].L;
D = jsonArray[i].D;
BP = jsonArray[i].BP;
LP = jsonArray[i].LP;
Points = jsonArray[i].Pts
html += “<tr><td align=’left’><font size=’+1′><b>”+pos+”</b><td><b>”+team+”</b></font></td></tr><tr><td>”+p+”</td><td>”+w+”</td><td>”+L+”</td><td>”+D+”</td><td>”+BP+”</td><td>”+LP+”</td><td>”+Points+”</td></tr>”;
}html += “</table>”;
Thanks
- The topic ‘Parsing Tablepress table with PHP’ is closed to new replies.