<?php require_once 'Keeper.php'; /* * For example: * You have created the site menu in the header and footer. * These menus are created in different files (modules), using the same array, * which returns a function mysql_fetch_assoc(); */
# file (module) generation head menu $query = "SELECT * FROM `menu` ORDER BY `sort` ASC"; $result = mysql_query($query); $menu = mysql_fetch_assoc($result);
# and file (module) generation footer menu $query = "SELECT * FROM `menu` ORDER BY `sort` ASC"; $result = mysql_query($query); $menu = mysql_fetch_assoc($result);
# Well... I propose to change the approach. # file (module) generation head menu $key_by_keeper_registry = 'Menu array assoc'; if (Keeper::exists($key_by_keeper_registry)) { $menu = Keeper::get($key_by_keeper_registry); } else { $query = "SELECT * FROM `menu` ORDER BY `sort` ASC"; $result = mysql_query($query); $menu = mysql_fetch_assoc($result); Keeper::set($key_by_keeper_registry, $menu); } # and file (module) generation footer menu $key_by_keeper_registry = 'Menu array assoc'; if (Keeper::exists($key_by_keeper_registry)) { $menu = Keeper::get($key_by_keeper_registry); } else { $query = "SELECT * FROM `menu` ORDER BY `sort` ASC"; $result = mysql_query($query); $menu = mysql_fetch_assoc($result); Keeper::set($key_by_keeper_registry, $menu); } ?>
|