Welcome Guest, Not a member yet? Register   Sign In
How do you insert data into multiple different tables at a time?
#2

This is from a blog that I' am working on.

You can see that I get an instance to all 3 models.

PHP Code:
    // -------------------------------------------------------------------

    /**
     * post ()
     * -------------------------------------------------------------------
     *
     * @param int $id
     */
    
public function post(int $id 0)
    {
        
$posts      = new PostModel($this->request);
        
$categories = new CategoryModel();
        
$comments   = new CommentModel($this->request);

        
$data = [
            
'posts'      => $posts->getPost($id),
            
'comments'   => $comments->getComments($id),
            
'categories' => $categories->getTopCategories(),
            
'titles'     => $categories->getCategoryTitles($id),
            
'title'      => 'Blog Post',
            
'typography' => Services::typography(),
        ];

        
$data['pageHeading'] = $data['titles']['title'];
        
$data['subHeading']  $data['posts']['sub_title'];

        
// Make all variables global to all views...
        
echo view('Insitefx\Blog\Views\view_data'$data);
        echo 
view('Insitefx\Blog\Views\post\index');
    } 

In the $data section you can see how I' am reading from all 3 tables PostModel, CategoryModel and CommentModel.

You should have a separate Model for each of your tables.

You would do everything like above for Inserting, Updating and Editing.

Hope that will get you started, would be best to read the User Guide on Working with Databases and Modeling Data.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: How do you insert data into multiple different tables at a time? - by InsiteFX - 08-12-2020, 06:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB