generate data from mysql only once and then save it?

it's hard to explain so I will just say what I have and what I need

I generate 3 arrays with data (a lot of data) from mysql (every time) when user visits any page. I need this for select options in the header of page

overall number of strings ~4000


$a[1]['desc']="balallbal desc";

$a[4000]['name']="balallbal 4000";

$a[4000]['desc']="balallbal desc 4000";

Can I somehow store this data instance or smth so when user goes to another page it would use stored data and not query mysql


You may want to try memcache. Store your result in memcache when user first request comes in and for next subsequent request you can pull the data from memcache instead of querying sql. Also the time for which data is to be stored in cache is configurable.

Yes you can. you must use $_SESSION for this. $_SESSIONs store data through the pages until the user closes the browser.

do this:

if($_SESSION['data-query'] == '')
   $data_array = get_data_from_db();
   $_SESSION['data-query'] = true; // to prevent the next data query
   $_SESSION['cat-data'] = $data_array;

Or you can use the count($_SESSION['cat-data']) == 0 instead of 'data-query` (as mentioned in the comment)

Use $_SESSION variable, it keeps your data while user surfs the site.

Check if this variable exists and has your data in the beginning of your code (something like start.php, init.php, header.php. Include it in all your pages). If not - fill it with mysql query one time and than use $_SESSION on other pages.

Need Your Help

Change background of mapped image hotspot on mouseover

javascript html css imagemap

I have an image map of 3 polygons. The actual image hotspots are complex shapes consisting of multiple curves and edges.

Resource file can't be located by eclipse android

android eclipse resources

I need help badly. I tried to to a clean in my android app Project>Clean. After doing this, All my classes started to have errors. It can't detect the R in --> findViewById(; And it ...