tags:

views:

55

answers:

4

When I use ajax, I have to use mysql_query again to get information in that file which is for ajax. Can I do action without mysql_query like with include();? Ask if you don't understand, because I guess I asked not very properly.

edited: When I try to reach ajax file, in that file I have to retrieve member information again. So, my question is, is it possible to avoid that?

A: 

You're going to have to rephrase your question better Tomas, because I've literally got no idea what you're trying to achieve.

Jamie Rumbelow
This should be a comment, not an answer.
Mark Byers
And this definitely shouldn't be an accepted anwer.
Tatu Ulmanen
Sorry, it was my fault, I unchecked that.
hey
A: 

Each access to a PHP page on the server is an isolated action. Results are not cached between accesses unless explicitly cached, e.g. in the session.

Ignacio Vazquez-Abrams
+1  A: 

Use a combination of content negotiation and caching, e.g

Controller
    Action
        // check if query is cached
        if(!Cache->hasSaved(Query))
            Result = Query->run
            Cache->save(Result)
        else
            Result = Cache->getSaved(Query)

        // check if Request was done via Ajax
        if(Request->isAjax)
            View->disableLayout
            View->set(JSON->encode(Result))
        else
            View->set(Result)

Like Ignacio explained, each requests to the server is isolated. PHP has a shared nothing architecture, so the only thing you can do to prevent the query from running again is to cache it. Content negotiation just helps to use the same query and return it on the depending request context, so you dont have a Controller Action for Ajax and one for regular calls.

Gordon
A: 

You could implement a caching layer, i.e. memcache or APC, which would allow you to store database results by key which would allow you to skip database access on subsequent calls.

cballou