Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    way to make function faster?

    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...


    PHP Code:
    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.
    Last edited by sitNsmile; 04-01-2010 at 07:28 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    For starters, do you actually need to select all columns for the result?

    Code:
    SELECT * FROM $gameTable

  • #3
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by MattF View Post
    For starters, do you actually need to select all columns for the result?

    Code:
    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. ?

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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.

  • #5
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by MattF View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •