Welcome Guest, Not a member yet? Register   Sign In
View files with common data
#7

[eluser]Sumon[/eluser]
I have a block of code which might help you to construct an array in model where data are from different tables. Although we can read data from multiple table in many ways, but the following code is more useful than that. Because you can apply any logic very easily.

Here goes the controller
Code:
$Data['PhotoComments']=$this->Photo->PhotoCommentsByPhotoId($PhotoId);
$this->load->view('photo/view_photo',$Data);

Model
Code:
$query = $this->db->query("SELECT Com.*, Login.mem_id, Login.mem_primary_photo, Profile.mem_first_name, Profile.mem_last_name FROM image_gallery_image_comment Com, member_login Login, member_profile Profile WHERE Com.image_id='$PhotoId' AND Com.mem_id=Login.mem_id AND Profile.member_id=Login.mem_id");
if ($query->num_rows() > 0)
{
    $i=0;
    foreach($query->result() as $val):
            //Apply any logic here
        foreach($val as $Key=>$Value):
            $Comments[$i][$Key]=nl2br($Value);//echo $key."|"$val."<br>";
        endforeach;
        $i++;
    endforeach;
    return $Comments;
}
else
    return FALSE;

Finally View:
Code:
for($i=0;$i<count($PhotoComments);$i++)
{
  echo $PhotoComments[$i]['mem_last_name'];
}
Hope this help you.


Messages In This Thread
View files with common data - by El Forum - 09-05-2008, 12:06 AM
View files with common data - by El Forum - 09-05-2008, 01:00 AM
View files with common data - by El Forum - 09-05-2008, 01:10 AM
View files with common data - by El Forum - 09-05-2008, 01:40 AM
View files with common data - by El Forum - 09-05-2008, 01:42 AM
View files with common data - by El Forum - 09-05-2008, 01:47 AM
View files with common data - by El Forum - 09-05-2008, 02:53 AM
View files with common data - by El Forum - 09-05-2008, 02:57 AM
View files with common data - by El Forum - 09-05-2008, 03:11 AM
View files with common data - by El Forum - 09-05-2008, 03:14 AM
View files with common data - by El Forum - 09-05-2008, 06:35 AM
View files with common data - by El Forum - 09-05-2008, 07:18 AM
View files with common data - by El Forum - 09-05-2008, 07:40 AM
View files with common data - by El Forum - 09-05-2008, 08:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB