Welcome Guest, Not a member yet? Register   Sign In
DB related code - make it simple and fast
#1

[eluser]Yash[/eluser]
Code:
//GetCats
$query = $this->db->get('categories');
             $i=0;
            foreach ($query->result() as $row)
            {
                $categories[$i]= array(
                                "CatID"=>$row->CatID,
                                "Cat"=>$row->Cat,
                                "RSS"=>$row->RSS,
                                "CatPrivate"=>$row->CatPrivate,
                                "ParentID"=>$row->ParentID
                                );    
                                
                $i++;

retrun $categories;

Code:
$cats=self::GetCats();

$categories=$posts['CatID']; //contain only numeric catids like 2,3,5 or 3 only
        $singlecategories=explode(",",$categories);
        //echo print_r($singlecategories);
        $mycat="";
        for($i=0;$i<=count($cats)-1;$i++)
        {
            for($j=0;$j<=count($singlecategories)-1;$j++)
            {
                if($singlecategories[$j]==$cats[$i]['CatID'])
                {
                    $mycat.=$cats[$i]['Cat'].",";
                }
            }
        }
        echo $mycat;

Please make it fast or simple code Smile


Messages In This Thread
DB related code - make it simple and fast - by El Forum - 06-26-2008, 04:44 AM
DB related code - make it simple and fast - by El Forum - 06-26-2008, 05:56 AM
DB related code - make it simple and fast - by El Forum - 06-26-2008, 06:16 AM
DB related code - make it simple and fast - by El Forum - 06-26-2008, 06:34 AM
DB related code - make it simple and fast - by El Forum - 06-27-2008, 01:32 AM
DB related code - make it simple and fast - by El Forum - 06-27-2008, 01:40 AM
DB related code - make it simple and fast - by El Forum - 06-27-2008, 01:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB