...

View Full Version : way to make function faster?



sitNsmile
04-01-2010, 08:09 PM
Okay. I've got a client that has some large websites, and need to be sure when I build the functions its as fast as possible... with showing you my function of querying results for games, (the database query system is already using caching (apc). but with code here, would something like this big okay, or is there ways to improve code that I already put together?

Just looking for new ideas...




public function queryGames($order,$oType,$limit,$active){

$gameTable = $this->_gameTable;
$gameStatus = $this->_gameStatus;

/* ORDER presets */
switch($order)
{
case 'ID':$gameOrder = $this->type0;break;
case 'DATE':$gameOrder = $this->type1;break;
case 'RANDOM':$gameOrder = $this->type2;break;
case 'RATING':$gameOrder = $this->type3;break;
case 'TOTALPOPULAR':$gameOrder = $this->type4;break;
case 'TODAYPOPULAR':$gameOrder = $this->type5;break;
}

$orderType = $oType == 'DESC' ? 'DESC' : 'ASC' ;
$statusType = $active == true ? "$gameStatus='1'" : "$gameStatus>='0'" ;

$sql = "SELECT * FROM $gameTable
WHERE $statusType
ORDER by $gameOrder $orderType
LIMIT $limit";

return $runSql = $this->_db->arcade->fetchAll($sql);

}


trying to do low procedural coding as possible.

MattF
04-01-2010, 08:30 PM
For starters, do you actually need to select all columns for the result?



SELECT * FROM $gameTable

sitNsmile
04-01-2010, 08:32 PM
For starters, do you actually need to select all columns for the result?



SELECT * FROM $gameTable



The idea, is making it dynamic for future changes, if database was changed, it would be an easy variable to just change the table which has been altered. Not sure if that would make so much of a difference. ?

MattF
04-01-2010, 08:36 PM
Select only what you need and no more. If the DB is designed/named correctly, there should be no need of future changes. But, if you want to future proof it, pass an array into the function containing the required fields. You can alter it in the same places where you would need to alter the code anyhows.

sitNsmile
04-01-2010, 08:41 PM
Select only what you need and no more. If the DB is designed/named correctly, there should be no need of future changes. But, if you want to future proof it, pass an array into the function containing the required fields. You can alter it in the same places where you would need to alter the code anyhows.


well besides that, I changed those over, cause I liked how it did look, but its only code. I'll go with this and see. takes a few bytes off the memory. But overall. would that be an okay function, I'm testing different methods because I go and finish the entire application, I want to be sure its how I want to build it so I dont waste time changing things later.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum