Ben iki foreach ifadeleri var. Bir birinden değişken bir şekilde başka içine oluyor ve ben bunu düzeltmek için nasıl emin değilim.
İşte benim denetleyicisi bulunuyor:
// Categories Page Code
function categories($id)
{
$this->load->model('Business_model');
$data['businessList'] = $this->Business_model->categoryPageList($id);
$data['catList'] = $this->Business_model->categoryList();
$data['featured'] = $this->Business_model->frontPageList();
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$data['page_title'] = 'Welcome To Jerome - Largest Ghost Town in America';
$data['page'] = 'category_view'; // pass the actual view to use as a parameter
$this->load->view('container',$data);
}
Ne olur kategoriler sadece belli bir kategoride işletmeler olarak gösterecektir.
Işletmelerin categoryPageList ($ id) işlevini kullanarak veritabanından çekilir.
İşte bu işlevi:
function categoryPageList($id) {
$this->db->select('b.id, b.busname, b.busowner, b.webaddress, p.thumb, v.title, c.catname, s.specname, p.thumb, c.id');
$this->db->from ('business AS b');
$this->db->where('b.category', $id);
$this->db->join('photos AS p', 'p.busid = b.id', 'left');
$this->db->join('video AS v', 'v.busid = b.id', 'left');
$this->db->join('specials AS s', 's.busid = b.id', 'left');
$this->db->join('category As c', 'b.category = c.id', 'left');
$this->db->group_by("b.id");
return $this->db->get();
}
Ve burada görünümü:
<h2>Welcome to Jerome, Arizona</h2>
<p>Choose the Category of Business you are interested in:<br/> <?php foreach ($catList->result() as $row): ?>
<a href="/site/categories/<?=$row->id?>"><?=$row->catname?></a>,
<?php endforeach; ?></p>
<table id="businessTable" class="tablesorter">
<thead><tr><th>Business Name</th><th>Business Owner</th><th>Web</th><th>Photos</th><th>Videos</th><th>Specials</th></tr></thead>
<?php if(count($businessList) > 0) : foreach ($businessList->result() as $crow): ?>
<tr>
<td><a href="/site/business/<?=$crow->id?>"><?=$crow->busname?></a></td>
<td><?=$crow->busowner?></td>
<td><a href="<?=$crow->webaddress?>">Visit Site</a></td>
<td>
<?php if(isset($crow->thumb)):?>
yes
<?php else:?>
no
<?php endif?>
</td>
<td>
<?php if(isset($crow->title)):?>
yes
<?php else:?>
no
<?php endif?>
</td>
<td>
<?php if(isset($crow->specname)):?>
yes
<?php else:?>
no
<?php endif?>
</td>
</tr>
<?php endforeach; ?>
<?php else : ?>
<td colspan="4"><p>No Category Selected</p></td>
<?php endif; ?>
</table>
Sorun burada oluşur. <?=$crow->id?> iş tablosundan satır kimliği gösteren olmalıdır. Bunun yerine, bu kategori tablonun satır kimliğini gösteriyor. I / site/categories/6 inceleyen kulüpler eğer şu anda bu kategorideki tek iş 10 (satır kimliğini göstermesi gerektiğini, bu nedenle zaman <?=$crow->id?> 6 gösterecektir.
Bunu nasıl düzeltebilirim?