(1) On server side I have a piece of PHP code that takes data from DB and converts them into a sort of Javascript array/matrix, let's just simply call it the PHP_OUTPUT
(2) On client side I have a piece of Javascript code that takes the PHP_OUTPUT and renders it as an HTML table.
Unfortunately Google does not read Javascript, so if I want Google to see the contents of the HTML table, I must write down in page the real HTML of the table. So now I need a NEW piece of PHP code to create by itself the SAME HTML table created by the Javascript code.
One way is obviously to rewrite in PHP all the Javascript code that renders the HTML table. Code rewriting is a sport that I don't like much.
Another way (I don't know if possible) is in some way to:
a) have (1) to pass the PHP_OUTPUT to (2),
b) then (2) creates the HTML table and sends (in some way) back the HTML source of the table to server,
c) finally the NEW piece of PHP code on server just writes down the source with a simple echo.
It's convoluted, but this would reduce the amount of code to be written to almost zero.
But is there a simple way to do this kind of stuff?
Hope you understand what I wrote, plz comments to ask for explanations.
Thanks for any answer.
-
1Come on. Writing that php generated tables should be 10 min work MAX. Probably less than time you took asking thisZ. Zlatev– Z. Zlatev2010年11月18日 19:02:43 +00:00Commented Nov 18, 2010 at 19:02
-
@Zlatev: if you want I give you the code to write. Just kidding. I did not explain everything on the question because I did not want it to become too confused. Writing a PHP to dump a simple table is not an issue, the problem is that the HTML TABLE rendered by Javacript is very complicated, contains classes on each column to distinguish rendering between strings/int/dates etc, moreover the PHP function interface takes input parameter in a special format that I would like to preserve: it lets you change headers and define column types.Marco Demaio– Marco Demaio2010年11月18日 19:15:09 +00:00Commented Nov 18, 2010 at 19:15
-
This isn't super helpful since it's all alpha-level code, but this is pretty neat developer.yahoo.com/yui/theater/video.php?v=glass-nodePeter Bailey– Peter Bailey2010年11月18日 20:31:46 +00:00Commented Nov 18, 2010 at 20:31
2 Answers 2
If you are able to create the HTML on the server side, then why do you need JavaScript at all? I would say the simplest way, would be to use your PHP code that creates the HTML that you need and get rid of the JavaScript all together.
5 Comments
Could you not simply have the PHP also dump the DB data into a hidden div of some sort? If it is simply for indexing purposes, it does not necessarily have to be in a human-readable table format, right?