How would I do this in php?
source link: https://www.codesd.com/item/how-would-i-do-this-in-php.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How would I do this in php?
I'm implementing a memcache to cache mysql query results.
It loops thru the mysql results using
while($rowP3= mysql_fetch_array($result3)) {
or it loops thru the memcached results (if they are saved in memcache, and not expired) via
foreach($cch_active_users_final as $rowP3) {
This is probably something thats really obvious... but Im not getting it.
How can I get it to show the right looping method based on if the memcached value exists or not. I just want it to pick the right looping method. I could just duplicate the entire while { } function with all its contents, but I dont wanna repeat that huge chunk of code, just so I can change while to foreach
Any tips?
The logic should be something like:
(partial pseudocode)
$data = get_memcached_data('cch_active_users_final');
if (!$data) {
$query = mysql_query(..);
$data = array();
while($row = mysql_fetch_array()) {
$data[] = $row;
}
store_in_memcache('cch_active_users_final', $data);
}
// do whatever you want with $data
Related Articles
How would you do this php code?
How would I configure this?
How would you build this daily class?
How would you solve this GPS location and scale problem? Do you use a database? R-tree?
How would you analyze this line of ingredients?
How would you do this type of painting animation on a text?
How would I call this method the viewDidLoad method?
How would I change this regular expression to accept a simple decimal of .5 at the end?
How would I parse this URL to get the ID?
How would you design this relational database?
How would you solve this handshake problem of graphic theory in python?
How would I launch this collection in a Ruby-Esque way?
How would you conceive this DB?
How would I move this floating div?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK