[eluser]sore eyes[/eluser]
Hi, I am newbie to codeigniter, so please bear with me. I have a database of shops and products they sell. I have set up codeignter so that I can cycle through each shop, one at a time and list the products that each shop can sell. The list of products is in checkbox form and needs to show a value of y/n depending on whether or not the shop sells the product. And that is the tricky part and I am stuck. Your help would be much appreciated.
The controller index is:
Code:
function enterShop()
{
$data['main'] = 'shop_view';
$data['title'] = "Shop";
$shop_id = $this->uri->segment(3);
$data['query'] = $this->MShops->getOneShop($shop_id);
$data['query2'] = $this->MProducts->getProducts();
$data['query3'] = $this->MProductsbyshop->getProductsbyshop($shop_id);
$this->load->vars($data);
$this->load->view('template');
}
Where the models are:
Code:
function getProducts()
{
$this->db->select('product_id, product');
$this->db->where('type_of_shop_id', 2);
$this->db->order_by('product');
$data = $this->db->get('products');
return $data;
}
function getProductsbyshop($shop_id)
{
$this->db->select('product_id');
$this->db->where('shop_id',$shop_id);
$data = $this->db->get('productsbyshop');
return $data;
}
Ending up with the view 'shop_view'
Code:
<?php foreach ($query3->result() as $row):?>
<?php $row->product_id; ?><br/>
<?php $new_product_id=$row->product_id; ?>
<?php echo $new_product_id; ?>
<?php endforeach ?>
<div id="floatright">
<?php foreach ($query2->result() as $row):?>
<p><?php echo form_checkbox('product', true, set_checkbox());?>
<?php //$row->product_id; ?>
<?php echo $row->product; ?></p>
</form>
<?php endforeach ?>
The view ends up showing the details for each shop, a list of all products, and a list of products that each shop sells (for show purposes). I need to combine the latter two, showing instead the check boxes with relevant ones ticked.
I hope I've explained this okay. Again your help would be much appreciated.