Welcome Guest, Not a member yet? Register   Sign In
populating a checkbox from database
#1

[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):?>
&lt;?php $row->product_id; ?&gt;<br/>
&lt;?php $new_product_id=$row->product_id; ?&gt;
&lt;?php echo $new_product_id; ?&gt;
&lt;?php endforeach ?&gt;

<div id="floatright">

&lt;?php  foreach ($query2->result() as $row):?&gt;
<p>&lt;?php echo form_checkbox('product', true, set_checkbox());?&gt;
&lt;?php //$row->product_id; ?&gt;
&lt;?php echo $row->product; ?&gt;</p>
&lt;/form&gt;
&lt;?php endforeach ?&gt;


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.


Messages In This Thread
populating a checkbox from database - by El Forum - 01-11-2009, 08:27 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:11 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:17 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:31 PM
populating a checkbox from database - by El Forum - 01-11-2009, 09:43 PM
populating a checkbox from database - by El Forum - 01-12-2009, 07:27 AM
populating a checkbox from database - by El Forum - 01-12-2009, 08:22 AM
populating a checkbox from database - by El Forum - 01-15-2009, 08:40 PM
populating a checkbox from database - by El Forum - 01-15-2009, 09:53 PM
populating a checkbox from database - by El Forum - 01-16-2009, 01:23 AM
populating a checkbox from database - by El Forum - 01-16-2009, 06:01 AM
populating a checkbox from database - by El Forum - 01-16-2009, 08:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB