1

I have a mysql table as follows:

users:
id | active | status | fname | lname | password

The result of "select*from users" is stored in memcache.

Lets say that I have 50 users, and rather than using php to format the results of the select*query, is it possible to just send the result of the query directly to javascript?

I would like php to do as little as possible: ie,

1) retrieve data from memcache/mysql
2) send $rows array to javascript (where $rows is the result of select*from users)

Javascript can then loop over the retrieved array to display the data in html.

QUESTION:

Is it possible to send result array directly to javascript, where the data can be looped over and outputted in html?

Is this a valid optimisation technique?

Are there any suggestions on how to perform this?

Any suggestions appreciated...

2
  • How is this an optimization? You still have to parse through all that data at some point, and now you have network latency as well. What are you expecting from this change? Commented Dec 25, 2011 at 18:33
  • 1
    "The result of "selectfrom users" is stored in memcache."* - For what reason do you do that? Commented Dec 25, 2011 at 18:35

2 Answers 2

1

Yes, this is certainly possible. It's not an uncommon technique: get JSON from server, make DOM out of it.

You could also render this page once, then store this HTML in memcache and serve it from there (without consulting your DB or rendering markup)

Sign up to request clarification or add additional context in comments.

Comments

0

first, you should remember that javaScript runs 'client-side'. Second, I think your server is far faster than your client's machine. I think you should do all processing server-side, then send the processed data to the client for display. To answer your question, consider using XML.

2 Comments

Well, server's processing power is shared between all clients, whereas a client is the only user of client machine. :-)
If someone wants efficiency, why on earth would you recommend XML?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.