Code optimisation assistance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Code optimisation assistance

Post by facets »

Hello all,

Is there a less complicated way to code the following

Code: Select all

<?
include_once "../includes/functions.inc.php";
include "../includes/common_db.inc";
include("template.inc");

//global $_REQUEST[$action];

$link_id = db_connect($db_materials);

if (isset($_POST['viewRecord'])) {viewPaperSummary($_POST['summaryId']);}
if (isset($_POST['viewFaceStock'])) {view($_POST['stockId']);}
if (isset($_POST['viewAdhesive'])) {viewAdhesives($_POST['adhesiveId']);}
if (isset($_POST['viewLiner'])) {viewLiners($_POST['linerId']);}
if (isset($_POST['searchNow'])) {fnSearchResults();}
if (isset($_POST['editSASummary'])) {view($_POST['summaryId']);}
if (isset($_POST['deleteSummary'])) {deleteSum($_POST['summaryId']);}
if (isset($_POST['submit'])) {updateSummary(); viewSearch();}
if (isset($_POST['viewSearch'])) {viewSearch();}

// Set varibale for switch action 
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; 

switch($action) {

    case "editStockSpec":		fnViewFaceStockSpec();  break;
    case "editAdhesiveSpec":    fnViewAdhesiveSpec();   break;
    case "editLinerSpec":       fnViewLinerSpec();      break; 
    case "editSASummary":       editSASummary();		break;
    case "viewStockSpec":       fnViewFaceStockSpec();  break;
    case "viewAdhesiveSpec":    fnViewAdhesiveSpec();   break;
    case "viewLinerSpec":       fnViewLinerSpec();      break;        
    case "viewAddFaceStock":    fnAddFaceStock();       break; 
    case "addAdhesive":         fnAddAdhesive();        break;
    case "addLiner":            fnAddLiner();         	break;
    case "addFs":				fnCreateFs();         	break;   
    case "addFaceStock":		viewAddFaceStock(); 	break;
    case "addSAStockSummary" :	addSAStockSummary();    break; 
    case "Update" :				updateSummary();    	break;        
    case "submit" :				updateSummary();    	break;  
    case "searchNow" : 			fnSearchResults(); 		break;
    case "viewPaperSummary": 	fnViewColloPaper(); 	break;
    case "delete_record": 		delete_record(); 		break;
    case "viewSearch" :			viewSearch(); 			break;
   	default:        			showMenu();				break;  
   } 

    $tmpl->set_block('page', 'footer');
    $tmpl->pparse('out', 'footer');
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

considering there are many many many paths, not really......
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

Hi, Does this make it a little easier to judge?
TIA, Wiil

Code: Select all

<?
include_once "../includes/functions.inc.php";
include "../includes/common_db.inc";
include("template.inc");

//global $_REQUEST[$action];

$link_id = db_connect($db_materials);

if (isset($_POST['viewRecord'])) {
	viewPaperSummary($_POST['summaryId']);
}

if (isset($_POST['submit'])) {
	updateSummary(); viewSearch();
}

if (isset($_POST['viewSearch'])) {
	viewSearch();
}

// Set varibale for switch action
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

switch($action) {

    case "viewPaperSummary":
	fnViewColloPaper();
	break;
    
    case "Update" :
	updateSummary();
	break;  

    case "searchNow" :
	fnSearchResults();
	break;

    default:
	showMenu();
   }
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

still the same basic issue.. there are many paths for the code to take through execution...
facets
Forum Contributor
Posts: 273
Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit

Post by facets »

OK.. thanks feyd.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

That code seems to be as optimized as it could get. Since the IFs aren't complex in any way, the code will still be executed (unless your functions are complex) very quickly since PHP is very fast. If you're worried about optimization for readability issues, a lot of extra comments wouldn't hurt anything. ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply