我想要来自三个表的数据,例如Ad_ID标题价格以及来自车辆和移动表格以及来自ref_listing_type表格的列表
我在控制器中的代码是
$data['my_ads']=$this->My_Profile->get_My_Ads();
我在模型中的代码是
function get_My_Ads(){$query = $this->db->select('AV.Ad_ID, AV.Title, AV.Price, LT1.Listing','AMP.Ad_ID,AMP.Ad_Title as Title,AMP.Price,LT.Listing')
->from('ad_vehicle AV')
->from('ad_mobile_phones AMP')
->join('ref_listing_type LT1', 'AV.Listing_Type_ID = LT1.Listing_ID','inner')
->join('ref_listing_type LT' ,'LT.Listing_ID = AMP.Listing_Type','inner')
->where('AV.Created_By', $_SESSION['user_id'])
->where('AMP.Created_By','2')
->get();return $query->result_array();}
我的视图中的代码是
<center><h2>My Ads</h2></center> <?php if(!isset($my_ads)){?><span class="name">NO ATA FOUND</span><?php } else { $cnt = 1;?><table width="95%" style="margin: 0 auto;" lass="list"><tr><th>Sr.No.</th><th>AD ID</th><th>AD TITLE</th><th>PRICE</th><th>LISTING</th><th>Action</th></tr> <?php var_dump($my_ads); ?><?php foreach($my_ads as row){?><tr> <td><label><?php echo $cnt;?></td><td><?php echo $row['Ad_ID'];?></td><td><?hp echo $row['Title'];?></td><td><?php echo $row['Price'];?></td><td><?php echo row['Listing'];?></td><td><a href="<?php echo base_url();?index.php/classified/MyProfile/edit_my_ad/<?php echo $row['Ad_ID'];?>">Edit</a> | <a href="?php echo base_url();?>index.php/classified/MyProfile/delete_my_ad/<?php echo row['Ad_ID'];?>" onClick="return areYouSure();">Delete</a></td></tr><?php $cnt++;}} ?></table>
我得到了结果
Sr.No. AD ID AD TITLE PRICE LISTING Action
1 40 Pulsur 8788.00 Free Edit | Delete
2 40 Pulsur 8788.00 Free Edit | Delete
3 40 Pulsur 8788.00 Free Edit | Delete
4 40 Pulsur 8788.00 Free Edit | Delete
5 41 verna 65655.00 Free Edit | Delete
6 41 verna 65655.00 Free Edit | Delete
7 41 verna 65655.00 Free Edit | Delete
8 41 verna 65655.00 Free Edit | Delete
答案 0 :(得分:0)
您可以指定联接的类型。
CI用户指南中的: 如果需要特定类型的JOIN,可以通过函数的第三个参数指定它。选项包括:左,右,外,内,左外和右外