0

How would I do this in php?

 2 years ago
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?

advertisements

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?

Is there a better way to write the below, other then using a switch or if/else statement? Like is this a situation where a PHP's varaiable variable ( $$var ) could come to use? If so how would you write this code? $type = 2; switch ($type) { case 1:

How would I configure this?

I'm trying to put together this layout... ... but I'm having issues with the middle section. The left section (with the MP3 icon) is ALWAYS aligned left and has fixed width of 72px... the right section (with the READY text) is ALWAYS aligned right BU

How would you build this daily class?

What I want to do is very simple but I'm trying to find the best or most elegant way to do this. The Rails application I'm building now will have a schedule of daily classes. For each class the fields relevant to this question are: Day of the week St

How would you solve this GPS location and scale problem? Do you use a database? R-tree?

Suppose I have a people and their GPS coordinates: User1, 52.99, -41.0 User2, 91.44, -21.4 User3, 5.12, 24.5 ... My objective is: Given a set of coordinates, Out of all those users, find the ones within 20 meters. (how to do a SELECT statement like t

How would you analyze this line of ingredients?

I have a text area full of lines of ingredient; typically in a [quantity] [measurement] [ingredient] [additional] format. For example, a few ingredient lines might be: 1 tablespoon garlic, minced 1 cup bell pepper, chopped I want to be able to identi

How would you do this type of painting animation on a text?

Try to load this website, and hover the text: http://www.guillaumetomasi.com/ the effect is pretty nice. A sort of dynamic painting over it. How would you do this? Some starting point suggestions? Plugin? I guess it's plain HTML5/Canvas and SVG, isn'

How would I call this method the viewDidLoad method?

This question already has an answer here: how to fire mapView:didSelectAnnotationView 3 answers How would I call this method from the viewDidLoad method? - (void)mapView:(MKMapView *)mapview didSelectAnnotationView:(MKAnnotationView *)view { // code

How would I change this regular expression to accept a simple decimal of .5 at the end?

I have the following regex: /^(([0-2][0-9]{2}|3[0-5][0-9])|360)$/ This accepts numbers from 000-360. I also want it to accept the decimal .5 at the end. No other decimal should be accepted and it should also accept no decimal at all. Also 360.5 shoul

How would I parse this URL to get the ID?

I want to parse this url using ruby to get the id 33: http://www.domain.com/?id=33 How would I do this?With an regular expression like /\d+\z/. You can build such one using rubular for example. The given expression extracts the id under the condition

How would you design this relational database?

I've been given lot's of ideas that I had no idea how they would translate into real life, I've just designed my first one to many table schema so please bear with me :) I have an events table that contains information such as music genres. What I di

How would you solve this handshake problem of graphic theory in python?

I graduated college last year with a degree in Psychology, but I also took a lot of math for fun. I recently got the book "Introductory Graph Theory" by Gary Chartrand to brush up on my math and have some fun. Here is an exercise from the book t

How would I launch this collection in a Ruby-Esque way?

puts "Renaming files..." folder_path = "/home/papuccino1/Desktop/Test" files = Dir.glob(folder_path + "/*").sort extension = File.extname(files[0]) puts File.basename(files[0], extension) puts "Renaming complete." M

How would you conceive this DB?

We are launching a website (paid subscription) and the sign up process includes entering an activation code. Activation codes are printed on scratch cards and sold via offline channels. Some of these cards are for 1 month access. Others are for 3 mon

How would I move this floating div?

I'm making a simple WordPress theme and I wanted to include a jQuery Sidr into and I got that done properly, however the menu icon that pulls the slide-in sidebar disappears behind the sidebar leaving the user with no way to collapse the sidebar agai

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK