[eluser]sore eyes[/eluser]
hi, I'm new to codeigniter and not much older with php, so please excuse.
I want to populate a form from a database. First by listing shops, then selecting one from the list to populate the form.
The controller is 'welcome':
Code:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
$this->load->helper('form');
$this->load->helper('url');
}
function index()
{
$data['query'] = $this->MShops->getShops();
$this->load->view('template',$data);
}
function enterShop()
{
$data['title'] = "Shop";
$shop_id = $this->uri->segment(3);
$data['query'] = $this->MShops->getOneShop($shop_id);
$this->load->view('shop_view',$data);
}
function shop_insert()
{
$this->db->insert('shop', $_POST);
redirect('welcome/enterShop/'.$_POST[shop_id]);
}
}
?>
Code:
The model is 'MShops':
<?php
class MShops extends Model{
function MShops(){
parent::Model();
}
function getShops()
{
$this->db->select('shopname,shop_id');
$data = $this->db->get('shop',10);
return $data;
}
function getOneShop($shop_id)
{
$this->db->where('shop_id', $shop_id);
$this->db->select('shopname,shop_id');
$data = $this->db->get('shop');
return $data;
}
}
?>
The views are 'template':
Code:
<?php foreach ($query->result() as $row):?>
<?=$row->shop_id; ?>
<?=$row->shopname; ?>
<?=anchor('welcome/enterShop/'.$row->shop_id, 'goto') ?> <br/>
<?php endforeach ?>
And view 'shop_view':
Code:
<h1><?=$title?></h1>
<?=form_open('welcome/shop_insert');?>
<?=form_hidden('shop_id', $this->uri->segment(3));?>
<?php $shop_id = $this->uri->segment(3); ?>
<p>Shop ID <input type="text" name="shop_id" value="<?=$shop_id?>" /></p>
<p>Shop Name <input type="text" name="shopname" value="<?=$shopname?>" /></p>
<p><input type="submit" value="submit" /></p>
I don't know what to use for "value" for the last piece of code.