Issue
I'm implementing a memcache to cache mysql query results.
It loops through the mysql results using
while($rowP3= mysql_fetch_array($result3)) { 
or it loops through the memcached results (if they are saved in memcache, and not expired) via
foreach($cch_active_users_final as $rowP3) {
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 don't want to repeat that huge chunk of code, just so I can change while to foreach
Solution
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
                        
                        Answered By - Joel L Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.