Welcome Guest, Not a member yet? Register   Sign In
question on db
#1

[eluser]mistress_shiira[/eluser]
hi guys!
im still not comfortable with CI so pls pardon my otherwise simple questions. Smile
im working on a certain admin page where that particular page shows the result from a query that i did.actually, what im confused here is how do i replicate the same thing that i did in CI?i mean,doing a query and echoing it as a table of results?
if i insert a function in my main controller for achieving that,how am i going to utilize the function in my view?

thanks again for any help on this...
#2

[eluser]llbbl[/eluser]
cool NWN icon. Smile
#3

[eluser]llbbl[/eluser]
Do the query in the controller and set the output to a variable in the data array. Then call your view sending the data array along with it. Then index your variable in the view file to display the results.

Code:
$query = $this->db->query( "SELECT * FROM `people` " );
  if($query->num_rows()>0){
    foreach($query->result() as $row){    
     $people[] = "<option value='$row->id'>$row->firstname $row->lastname </option>";
    }
  }
        
$data['people'] = $people;
#4

[eluser]mistress_shiira[/eluser]
thanks.i think i got the idea..Smile i'll try to implement this just to check if i really understood ur explanation..
#5

[eluser]leonards[/eluser]
You could just do it directly into your view file too but the important thing about MVC structure is to do all the "mechanism" in the controller and all the databases related communications in the model.

So, to push the MVC as far as you can you could

1. Put the $query = $this->db->query in a model

2. Do the loop in the controller and pass it to the view.
2a. ** Maybe some data validation stuff here before passing to view**

3. The view receive all cleaned datas and parse it to screen.




Theme © iAndrew 2016 - Forum software by © MyBB