Codeigniter-模型中的最后一行



我有三个包裹,如银、金、白金。我必须在包视图中显示这些包的最后一行。我为此创建了任何Model页面,但这段代码只显示表中最后一项的最后一行。例如,我有3个包,它只显示一个包的最后一个包。不显示其他包裹,如黄金和白银。我想将上次编辑的程序包与其他程序包一起显示。如果我编辑任何包,我想将上次编辑的包的最后一行与其他包一起显示。我该怎么做?

我的型号代码:

public function packages()
{
$this->db->select('
package.*, packageService.*
');
$this->db->from('packageService');
$this->db->join('package', ' package.packageService = packageService.packageServiceId');
$this->db->limit(1);
$this->db->order_by('packageId',"DESC");
$query = $this->db->get();
$results = $query->result();
return $results;
}

我的包裹视图:

<section id="main-content">
<section class="wrapper site-min-height">
<!-- page start-->
<div class="row">
<!--price start-->
<div class="text-center feature-head">
<h1> PACKAGES </h1>
<p>Choose Your Special Package Plan. </p>
</div>
<?php foreach($packs as $get) { ?>
<div class="col-lg-3 col-sm-3">
<div class="pricing-table <?php if ($get->packageNameEn == 'Platinum') { echo 'most-popular'; } ?>">
<div class="pricing-head">
<h1> <?php echo $get->packageNameEn; ?> </h1>
<h5><del>€ <?php echo $get->packagePrice ?></del></h5>
<h2><span class="note">€</span> <?php echo $get->packagePriceCut ?> </h2>
</div>
<ul class="list-unstyled">
<?php echo $get->packageServiceNameEn ?>
</ul>
<div class="price-actions">
<a class="btn" href="javascript:;">Get Now</a>
<a class="btn" href="<?php echo base_url("package/edit/$get->packageId"); ?>">Edit</a>
</div>
</div>
</div>
<?php } ?>
</div>
<!-- page end-->
</section>
</section>
<!--main content end-->

我建议将packageRev更改为默认值为0的packageParent。在此字段中,我们保留对原始包ID的引用。然后在你的模型

$this->db->select_max('packageId', 'MaxPackageId'); 
$this->db->select('IF(packageParent = 0 , packageId, packageParent) as parent', FALSE); 
$this->db->from('package'); 
$this->db->group_by('parent'); 
$subquery = $this->db->get_compiled_select(); 
$this->db->reset_query();
$this->db->select('package.*, packageService.*'); 
$this->db->from('package'); 
$this->db->join("($subquery) t1","t1.MaxPackageId = package.packageId"); 
$this->db->join('packageService', 'package.packageId = packageService.packageServiceId', 'LEFT');
$query = $this->db->get(); 

此外,你需要根据这个更新你的控制器

相关内容

  • 没有找到相关文章

最新更新