Welcome Guest, Not a member yet? Register   Sign In
how to send a table to the view
#1

[eluser]Zion.b.y[/eluser]
hi all,
i habe an sql statment that returs me a table,

i want to move that table to the view and i dont know how?

how do i send it and how do i reffer to the table in the view file

thanks a lot,please bring me examples,

thanks again,
Zion
#2

[eluser]stuffradio[/eluser]
You need to look at Models.

In the Model folder, I always create a file and name the filename the same as the name of the table I'm using.

So if I have a table called Users, and I have ID, Username, and Password here is what it would look like.

Path: /system/application/models/users.php

Code:
<?php

class Users extends Model
{

   var $ID; // I don't usually put an ID var
   var $Username; // Var that handles username
   var $Password; // Var for password

    function Users()
    {
      parent::Model();
    }

    function getUsers()
    {
      $query = $this->db->get('Users');
      return $query->result();
    }
}

In my controller file:
path: /system/application/controllers/controllerfile.php

Code:
<?php

class Controllerfile extends Controller
{

     function Controllerfile()
     {
        parent::Controller();
        $this->load->model('users');
     }

     function index()
     {
       $data['users'] = $this->users->getUsers();
       $this->load->view('myview', $data);
     }
}

View file:
path: /system/application/views/myview.php
Code:
<?php foreach ($users as $user): ?>
<h1>&lt;?=$user->Username;?&gt;</h1>
&lt;?php endforeach; ?&gt;


This is something quick and dirty, enjoy!
#3

[eluser]Zion.b.y[/eluser]
thanks a lot dude
liked the examples,
also, code ingiter very cool, i just started to use it.




Theme © iAndrew 2016 - Forum software by © MyBB