Accessing records from 2 tables in a single view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Accessing records from 2 tables in a single view (/showthread.php?tid=42858) |
Accessing records from 2 tables in a single view - El Forum - 06-22-2011 [eluser]shailendra[/eluser] I have controller dashboard.php which to fetch data from "bids" and "projects" table and display records from both the tables into dashboard_view.php. But in dashboard_view.php I get records from only "projects" table. How do I get records from 2 tables without using join?? The code for dashboard.php is Code: <?php and the code for dashboard_view.php is Code: <table width="95%" border="0" align="center" cellpadding="4" cellspacing="0" class="user1_inner"> Accessing records from 2 tables in a single view - El Forum - 06-22-2011 [eluser]Seb[/eluser] There is more than one way to do it, but your same dashboard view is called twice with the two datasets. Try this instead: Code: <?php and this for the view: Code: <table width="95%" border="0" align="center" cellpadding="4" cellspacing="0" class="user1_inner"> Accessing records from 2 tables in a single view - El Forum - 06-23-2011 [eluser]shailendra[/eluser] Thanks mate for your help.......It worked with your code. Accessing records from 2 tables in a single view - El Forum - 06-24-2011 [eluser]shailendra[/eluser] With reference to above code, I wanted to echo no. of records so I wrote this code Code: function index() How do I count no. of records? Accessing records from 2 tables in a single view - El Forum - 06-24-2011 [eluser]bEz[/eluser] http://ellislab.com/codeigniter/user-guide/database/active_record.html Don't take this as an insult, but certain questions like this are in the User Guide. There are questions which are a bit trivial, but not something like this. Accessing records from 2 tables in a single view - El Forum - 06-24-2011 [eluser]adityamenon[/eluser] Code: $data['projects']= $this->db->where('user_id', 1)->get('projects')->num_rows(); Accessing records from 2 tables in a single view - El Forum - 06-24-2011 [eluser]shailendra[/eluser] I'm not feeling offended........but I read this page on user guide....but could not find a solution.....also read CI forums...got "count_all" but it didnt help as it does does not work with "where" clause. But I found solution myself Code: echo count($projects); My question to you is - below line of code works in the Blog tutorial.Why doesn't it work in this case? Code: echo $projects->num_rows(); Accessing records from 2 tables in a single view - El Forum - 06-25-2011 [eluser]shailendra[/eluser] This line of code worked too. Thanks. Code: $data['projects']= $this->db->where('user_id', 1)->get('projects')->num_rows(); Accessing records from 2 tables in a single view - El Forum - 06-25-2011 [eluser]adityamenon[/eluser] [quote author="shailendra" date="1309002169"]This line of code worked too. Thanks. Code: $data['projects']= $this->db->where('user_id', 1)->get('projects')->num_rows(); cheers. |