开发者

PHP to Javascript and back to HTML design problem

(1) On server side I have a piece of PHP code that takes data from DB and converts them into a sort of Javascript开发者_StackOverflow中文版 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.


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜