Welcome Guest, Not a member yet? Register   Sign In
Using Models When Tables Are Unknown
#1

Hi there! Smile

I was wondering if anyone could help with this. I am basically trying to find out if it is possibly to use Models with unknown tables. Or if it is possible to create a Model that works with multiple tables.

As an EG:
The app I am creating displays Prize Giving Results. So one of the tables columns would be Place, Race Number, name, Age, Time. There can be many tables that have the same columns but different names according to the category EG: Men 30 - 35, Men 40 - 45 etc. Or some tables could have different columns.

I have the following code which gets a list of the tables which contain Results information.


PHP Code:
// Get a list of the results tables. 
// Tables should be prefixed with rs_
$tables $this->db->list_tables();
$data['tables'] = array();
foreach (
$tables as $table) {
    if (strpos($table'rs_') === 0) {
        
array_push($data['tables'], $table);
    }



What I need to do now is create the Models for those tables so that I can display and update them if necessary. 

So I am basically stuck as to how one would create the models beforehand if the tables are unknown. Is there a generic Model I could use that would work across all the tables? Would I have to create the Models with PHP after I have list of the table names?

I am still new to CodeIgniter and MVC's in general so thought I could ask and possibly get some assistance that could save me quite a few hours of figuring out how everything works.  


Thank you very much for any help!
Reply


Messages In This Thread
Using Models When Tables Are Unknown - by GregS - 01-16-2020, 03:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB