Welcome Guest, Not a member yet? Register   Sign In
Questions regarding <dl> in CI.
#11

[eluser]obiron2[/eluser]
If your array is only 2 levels deep, you may find it easier to fetch the years from the database into an array using a SELECT DISTINCT
and then append the event data into each array element using another db query with the year as a filter.

It may not be faster, as you have had to make three trips to the db server rather than one, but the data manipulation should really be done at the db level rather than at the PHP level. I'm not sure what the performance difference would be if you had say 5 years and 50,000 events - I would suspect that at some point multiple trips to the db would be faster than manipulating large arrays in PHP

another alternative would be to return a flat data set, properly sorted and then chuck out a DL tag on change of year, this way you don't have to manipulate the data set and you only have one query, the only issue is that you would have redundant data in the results set.


Obiron
#12

[eluser]überfuzz[/eluser]
[quote author="obiron2" date="1252082318"]If your array is only 2 levels deep, you may find it easier to fetch the years from the database into an array using a SELECT DISTINCT
and then append the event data into each array element using another db query with the year as a filter.Obiron[/quote]

I think I get the idea... Could you give me a hint on how I should write the query? This is a part of the model I was referring to earlier.

Code:
function get_array_to_dl($table_one, $column_one, $table_two,$coulmn_two,$link_column_one, $link_column_two,$order)
    {
        $this->db->select($table_one.'.'.$column_one.' AS when');
        $this->db->select($table_two.'.'.$coulmn_two.' AS event');
        $this->db->from($table_one);
        $this->db->join($table_two, $table_two.'.'.$link_column_two.' = '.$table_one.'.'.$link_column_one);

        $this->db->order_by($table_one.'.'.$link_column_one, $order);
    //etc...
    }
#13

[eluser]Aken[/eluser]
That is an insane amount of variables to pass through a single model function. It's perfectly acceptable (and recommended) to use a few methods with specific functionality, instead of something like that where you are still entering a ton of info into each call.

My recommendation? Make two model functions. One to pull the database information as it normally would (your first example). A second function - the one you'd actually use in this situation - would pull the DB info using the first function, and then format it specifically for the definition list.
#14

[eluser]überfuzz[/eluser]
[quote author="Aken" date="1252341503"]That is an insane amount of variables to pass through a single model function. It's perfectly acceptable (and recommended) to use a few methods with specific functionality, instead of something like that where you are still entering a ton of info into each call.

My recommendation? Make two model functions. One to pull the database information as it normally would (your first example). A second function - the one you'd actually use in this situation - would pull the DB info using the first function, and then format it specifically for the definition list.[/quote]

So your suggestion is as follows:
1. A specific model for each call? (In my case I have 5 different calls that have to be done in a similar way but to different sql-table. Each call fetches something like 2 or 10 rows.)
2. One function that alter the array, call this method from each query-method.
3. Pass the return the now altered array from each query-function.

Whats the downside in having a bunch of variables pass to a function in contrast to having a bunch of functions?
#15

[eluser]Aken[/eluser]
In my opinion, based on that model function you showed, you might as well be making the DB call directly. Passing SEVEN variables is crazy. Yes, if you have a handful functions that each reports some specific information even in a similar fashion, I would much prefer that over your method. You'd be doing "$this->model->functionTwo();" instead of "$this->model->function($blah, $blah, $blah, $blah);". It's far easier to manage.

You could even have a private function inside your model that does the actual DB retrieve, and just define some variables for each situation in the rest of your functions.

Code:
function getDB1()
{
    $params = array(
        'column1' => 'this',
        'column2' => 'this',
        'table1' => 'this',
        'table2' => 'this'
    );
    
    return $this->parse($params);
}

function getDB2()
{
    $params = array(
        'column1' => 'this',
        'column2' => 'this',
        'table1' => 'this',
        'table2' => 'this'
    );
    
    return $this->parse($params);
}

private function parse($params)
{
    $this->db->select($params['table1'].'.'.$params['column1'].' AS when');
    $this->db->select($params['table2'].'.'.$params['column2'].' AS event');
    
    return $this->db->return_array();
}
#16

[eluser]überfuzz[/eluser]
@akan - I wasn't really asking about you opinion when I asked about the upside and downside. But tnx for taking the time to answer, and the last example looks tempting.
#17

[eluser]Aken[/eluser]
[quote author="überfuzz" date="1252346304"]@akan - I wasn't really asking about you opinion when I asked about the upside and downside.[/quote]

Are you sure?

[quote author="überfuzz" date="1252342273"]Whats the downside in having a bunch of variables pass to a function in contrast to having a bunch of functions?[/quote]

You ask for suggestions on this forum, these are my suggestions. Your coding style is completely up to you, I'm just trying to help.

- Create separate functions that define certain variables for each set of data you need to return.
- Create a universal private function that will retrieve the information from the database using the variables supplied by individual functions. The info will then be returned to the functions, and in turn returned to your controllers.
- Create a function that formats a supplied array into the structure you need to loop into a definition list properly.
#18

[eluser]überfuzz[/eluser]
[quote author="Aken" date="1252350679"][quote author="überfuzz" date="1252346304"]@akan - I wasn't really asking about you opinion when I asked about the upside and downside.[/quote]

Are you sure?

[quote author="überfuzz" date="1252342273"]Whats the downside in having a bunch of variables pass to a function in contrast to having a bunch of functions?[/quote]

You ask for suggestions on this forum, these are my suggestions. Your coding style is completely up to you, I'm just trying to help.

- Create separate functions that define certain variables for each set of data you need to return.
- Create a universal private function that will retrieve the information from the database using the variables supplied by individual functions. The info will then be returned to the functions, and in turn returned to your controllers.
- Create a function that formats a supplied array into the structure you need to loop into a definition list properly.[/quote]

Maybe a PM is more suitable, but then again...

$akan - I asked for an explanation of why I should do it the way you suggested. (See post #13 if you missed out on it.) You failed in doing so. Describing what I posted as insane and crazy is hardly a suggestion. Thats only a rude way of stating your point of view or opinion if you will. By the way, even you called it an opinion in your post, and then you acted as if you were puzzled about that. ;-) Quite interesting actually! But lets leave it out of this forum. Lets stick to the parts were you actually manage to suggest stuff. Great stuff, tnx!
#19

[eluser]Aken[/eluser]
My opinion about the matter IS my explanation. I'm sorry if you misunderstood it in any way, but every single one of my posts explains the same process, just in varying detail. Good luck with your project.
#20

[eluser]überfuzz[/eluser]
[quote author="Aken" date="1252382897"]My opinion about the matter IS my explanation. I'm sorry if you misunderstood it in any way, but every single one of my posts explains the same process, just in varying detail. Good luck with your project.[/quote]
No, I did not miss your opinion, it was quite clear. quote: ...insane... ...crazy... Yes, you explain the same process, its mostly the insults that changes. My humble question was about the upsides and the downsides. It's clear to me now that its pointless to ask you.




Theme © iAndrew 2016 - Forum software by © MyBB