Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 03-17-2006, 08:33 AM   #1
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
PHP Experts, Optimization question

Looking to optimize a lengthy switch/case statement. Working on something like this, and considering how to optimize it and speed it up. It's not that slow yet but it might be when it's finished.

Code:
switch($var) {
  case 'val1':
      $action = 'step1';  break;
 case 'val2':
      $action = 'step2';  break;

 .. and so on for about 200 more of these ..

 default:
      $action = 'do the hokey pokey';  break;
}
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-17-2006, 09:49 AM   #2
Echo
Confirmed User
 
Join Date: Nov 2003
Posts: 158
if your $action are text/word try to put them in array() or store them in your database and call it in a limited query output
__________________
ICQ #228-338-185
Echo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-17-2006, 10:15 AM   #3
paterson3713
Confirmed User
 
Join Date: Nov 2005
Location: Edmonton, AB
Posts: 190
Yeah you could do like:
Code:
$actions['val1'] = 'step1';
$actions['val2'] = 'step2';

// Then, 
$action = $actions[$var];
Or, like it was also mentioned before, using a database:
Code:
// First, put the values into a mysql database like: value | action
// Then,
$action = @mysql_result(mysql_query('SELECT action FROM mySteps WHERE value=\''.mysql_escape_string($var).'\''),0);
__________________
paterson3713 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-17-2006, 10:53 AM   #4
s9ann0
Confirmed User
 
Join Date: Sep 2001
Location: Boston
Posts: 4,873
fuck that get your host to install a PHP cache!
s9ann0 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 03-17-2006, 11:08 AM   #5
mrkris
Confirmed User
 
Join Date: May 2005
Posts: 2,737
Quote:
Originally Posted by paterson3713
Yeah you could do like:
Code:
$actions['val1'] = 'step1';
$actions['val2'] = 'step2';

// Then, 
$action = $actions[$var];
Or, like it was also mentioned before, using a database:
Code:
// First, put the values into a mysql database like: value | action
// Then,
$action = @mysql_result(mysql_query('SELECT action FROM mySteps WHERE value=\''.mysql_escape_string($var).'\''),0);
Never mix storage with procedure. The easiest thing to do, would be something like:

$method = 'some' . $action;
if (method_exists(array(&$object, $method))) {
$function->$method;
}

I would do something like that ...
__________________

PHP-MySQL-Rails | ICQ: 342500546
mrkris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.