AJAX- Update Grid from array
Moderator: General Moderators
AJAX- Update Grid from array
HI!
I'm a newbie of this forum so I hope to not be "off topic".
My problem is this:
Can I update only some cells of my table?
I build my table from a bi-dimenional php array.
Sometimes only few field of this array change and I would like to update only the relative cells of the table.
Is it possible?
Thank for your help!
I'm a newbie of this forum so I hope to not be "off topic".
My problem is this:
Can I update only some cells of my table?
I build my table from a bi-dimenional php array.
Sometimes only few field of this array change and I would like to update only the relative cells of the table.
Is it possible?
Thank for your help!
Re: AJAX- Update Grid from array
It's certainly possible. We would need to see the code you use to build the table and a rough idea of what would be changing (and when) before we can give you more than just general help. How familiar are you with ajax and page manipulation using javascript?
Re: AJAX- Update Grid from array
Thanks for your help.
I must confess that I am looking forward to know the solution.
I've read a lot of thing in the internet and I think that the solution is in Ajax.
The code is something like that:
Every cells has got its ID, so I can immediately identify where I have the put the new value.
So As soon As the a field of the php array changes, the server PUSH the only new value to the client and this put the new value in the exact cell.
I must confess that I am looking forward to know the solution.
I've read a lot of thing in the internet and I think that the solution is in Ajax.
The code is something like that:
Code: Select all
<?php
echo '<table>';
for ($i=0; $i<count($array);$i++){
echo "<tr>";
echo "<td><div id='cell'.$i.'1'>";
print $array[$i]['ID-MATCH'];
echo "</div></td>";
echo "<td><div id='cell'.$i.'2'>";
print $array[$i]['RESULT'];
echo "</div></td>";
echo "<td><div id='cell'.$i.'3'>";
print $array[$i]['WHERE'];
echo "</div></td>";
echo "<td><div id='cell'.$i.'4'>";
print $array[$i]['WHEN'];
echo "</div></td>";
echo "<td><div id='cell'.$i.'5'>";
print $array[$i]['NOTE'];
echo "</div></td>";
echo "</tr>";
}
echo "</table>" ;
?>So As soon As the a field of the php array changes, the server PUSH the only new value to the client and this put the new value in the exact cell.
Re: AJAX- Update Grid from array
That's excellent, and makes this much easier to do. I just yesterday wrote a script that is fairly similar to what you need, as soon as I get home (at work now... I'm done in 45 minutes) I'll post it over here.cirom wrote:Every cells has got its ID, so I can immediately identify where I have the put the new value.
So As soon As the a field of the php array changes, the server PUSH the only new value to the client and this put the new value in the exact cell.
To get you started in the interim, take a look at this example of using AJAX. You're going to want to be pulling xml with ajax, and use the xml to populate the form (using javascript).
I am a little bit confused by your for loop... why does it display so many divs with the same id? Shouldn't each div have a unique id? EDIT: never mind, I understand it now... just had to look a little closer.
Re: AJAX- Update Grid from array
Yes every cell has its unique ID.
In the interim I'll take a look at your example.
In the interim I'll take a look at your example.
Re: AJAX- Update Grid from array
I think using JSON might be easier here, though admittedly I've never accessed XML with Javascript.
Get your PHP script (the script you'll call via AJAX) to generate an array. The keys would be the ids of the cells to update, and the values would be the new values. Run it through json_encode() & output it.
In your Javascript then, iterate through the properties of the returned object (json_encode() will turn your array into a string that Javascript will treat as an object) & for each property, update the appropriate cell.
Get your PHP script (the script you'll call via AJAX) to generate an array. The keys would be the ids of the cells to update, and the values would be the new values. Run it through json_encode() & output it.
In your Javascript then, iterate through the properties of the returned object (json_encode() will turn your array into a string that Javascript will treat as an object) & for each property, update the appropriate cell.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: AJAX- Update Grid from array
I can't use JSON.
I'm obliged to use this array.
However Can I see a demo and the code?
I have thought to create a php page that controls every two second,on the server, if the newest array has changed.
Then it values in which "ID cell" it has to push the new value.
I think to be capable to create this page but I don't know in which way I can push the update.
I'm obliged to use this array.
However Can I see a demo and the code?
I have thought to create a php page that controls every two second,on the server, if the newest array has changed.
Then it values in which "ID cell" it has to push the new value.
I think to be capable to create this page but I don't know in which way I can push the update.
Re: AJAX- Update Grid from array
Well you can't transfer & access a PHP array. You're going to have to convert it into something else in order to access it via Javascript.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: AJAX- Update Grid from array
ok.
Before converting in Json or Xml can I see the CODE that update the page?
Before converting in Json or Xml can I see the CODE that update the page?
Last edited by cirom on Fri Aug 08, 2008 2:24 pm, edited 1 time in total.
Re: AJAX- Update Grid from array
I don't understand your question.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: AJAX- Update Grid from array
If it is possibile I would read your code then I can use Json or Xml.
THXS
THXS