• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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

#2
See the Database Forge Class and Database Utility Class under Databases

Might help and be what your looking for.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
I have not read the docs properly yet (but I will!), but just from a glance it appears that the Datbase Forge is exactly what I am looking for!

Thank you for the help!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.