I am currently trying to create a sample shopping site,The problem came when I created a search page.In my search page I Have two fields one for enter the keyword and other for select type of item
Which means search,keyword in the selected item.but the item defined in DB is 0 and 1 and i Trying to get it my code but fails...could any one help me...
The Gfunction code is
public static function item(){
$optionList='';
$CategoryList = OfferEvents::model()->findAllByAttributes(array());
foreach($CategoryList as $catdata)
{ $optionList.="<option value='".$catdata['type']."'>".$catdata['name']."</option>"; }
return $optionList;
}
and view code is
<form action="<?php echo Yii::app()->baseUrl; ?>/offer?>" method="GET" class="form-inline form-section-2 row fadeInDown animated">
<div class="col-sm-5 form-group">
<input type="text" name="search" class="form-control" id="search" value="" placeholder="Enter Your Keyword">
</div>
<div class="col-sm-4 form-group">
<select name="cat" class="form-control selectpicker">
<option value='0'>Select type</option>
<?php echo GFunctions::item(); ?>
</select>
</div>
<div class="col-sm-3 form-group">
<button type="submit" class="btn btn-default btn-new">Search</button>
</div>
</form>
why don't you use Yii built in functions to handle the dropdown?
I am not sure how your Models looks like but you can choose one of the following functions to achieve what you want instead of trying to return a String $optionList with HTML tags.
CHtml::activeDropDownList() // for directly bind to active record model
CHtml::dropDownList()
Try this code....
Function
public static function item(){
$CategoryList = OfferEvents::model()->findAllByAttributes(array());
$optionList = CHtml::listData($countries, 'type', 'name')
return $optionList;
}
In view
<?php echo CHtml::dropDownList('cat', '', GFunctions::item(), array('prompt'=>'Select type'));?>
Related
in my Laravel App I have a Blade "Insert Project" where I want to dynamic load html data from Database when a DropDown changes. To be more concrete: I have several Project Categories in the Table "Cats" (id, name, code) - Each Category needs different fields to be added, therefore I have put the html code in the Table "Cats". I want to achieve the following:
If a user selects a Project Category the html code which is attached to the category should be shown.
My Code so far:
<form method="POST" action="{{ route('project-insert') }}">
#csrf
<form action="{{ route('filter') }}" method="post">
<label for="Cat">Kategorie</label>
<select class="form-control" name="cat_id" id="cat_id" data-parsley-required="true" onchange='this.form.submit()'>
#foreach ($cats as $sn)
{
<option value="{{ $sn->id }}">{{ $sn->name }}</option>
}
#endforeach
</select>
</form>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Add Project') }}
</button>
</div>
</div>
</form>
In my Controller I have add:
public function insertProject(Request $data) {
return $data['cat_id'];
}
public function filter(Request $request)
{
$cat_id = $request->input("cat_id");
return $cat_id;
$code = DB::table('cats')->where('id', '=', $cat_id);
var_dump($code->code);
}
When I change the DropDown, then the function "insertProject" will be called and not the desired function "filter".
How can I achieve it to call the correct function, or how can I achieve it to call "insertProject" only when the button has been pressed?
Thank you for your advice and help.
Stefan
How to get data by selecting the drop-down in CodeIgniter.
Below is my code it does not work. The below code is not working properly when I selecting an option in the drop down and when I submit page appearing empty. when click please help me to get data. I am doing it in CodeIgniter. I want to get data from the database . I think the code is perfect am new to CodeIgniter the below code is not working properly the page appearing empty when click please help me to get data. I am doing it in CodeIgniter. I want to get data from the database . I think the code is perfect am new to CodeIgniter.
view:
<?php echo form_open('super_admin/believers_controller/view_believerr/' , array('class' => 'form-horizontal validatable', 'enctype' => 'multipart/form-data') ); ?>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> District Id</label>
<div class="col-sm-9">
<select name="report_type" >
<option >Select Id</option>
<option value="believers">Believers</option>
<option value="staff">staff</option>
<option value="staff">committe members</option>
</select>
</div>
</div>
<div class="clearfix form-actions">
<div class="col-md-offset-3 col-md-9">
<input type="submit" name="Submit" class="btn btn-info" >
controller:
<?php
function view_believerr()
{
$report_type = $this->input->get('report_type');
if($report_type=='believers'){
$this->load->model('believers/believers_model');
$page_data['h']=$this->believers_model->view_believer();
$page_data['page_name'] = 'believers/view_believer';
$this->load->view('index', $page_data);
}
}
?>
model:
<?php
function view_believer()
{
$query = $this->db->get('tbl_believers');
return $query;
}
?>
I want to get data from database . I think the code is perfect am new to codeigniter the below code is not working properly the page appearing empty when click please help me to get data. I am doing it in codeigniter. I want to get data from database . I think the code is perfect am new to codeignite
Use $this->input->post('report_type');
the function sumqtyin() inside codeigniter model
function sumqtyin(){
$kdbahan = $_POST['kode_bahan_baku']; //i wanna echo a value from the input text kode_bahan_baku but it always says error "undefined index kode_bahan_baku"
$datenow = date("Y-m-d");
return $this->db->query("
SELECT IFNULL(SUM(qty_in),0) AS qty_in
FROM trans_stock_movement
WHERE tanggal_movement='$datenow'
AND status_aktif='YES' AND kode_bahan_baku = '$kdbahan' ");
}
my view input text for kode_bahan_baku inside a post form
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Bahan Baku</label>
<div class="col-sm-2">
<div class="input-group">
<input type="text" class="form-control" id="nama_bahan_baku" name="nama_bahan_baku" placeholder="Bahan Baku" value="" style="width:150px" required="required">
<input type="text" id="kode_bahan_baku" name="kode_bahan_baku" value="" class="form-control">
<div class="input-group-btn">
<button type="button" class="btn btn-info btn-flat" data-toggle="modal" id="btnMenu" data-target="#menuModal">
<i class="fa fa-fw fa-search"></i>
</button>
</div>
</div>
</div>
</div>
please help :(
Your controller is the go-between of your view and your model, as such, you should be grabbing the data out using $this->input->post('kode_bahan_baku') in the controller and passing those details through to the model:
Controller:
$kdbahan = $this->input->post('kode_bahan_baku');
$dbResultObj = $this->yourLoadedModel->sumqtyin($kdbahan);
then use the object $dbResultObj like: $dbResultObj->qty_in to get out the result
Model:
function sumqtyin($kdbahan){
$datenow = date("Y-m-d");
return $this->db->select('SUM(IFNULL(qty_in,0)) AS qty_in')
->where('tanggal_movement', $datenow)
->where('status_aktif', 'YES')
->where('kode_bahan_baku', $kdbahan)
->get('trans_stock_movement')
->result();
}
Please Follow the MVC structure , Before you make any manipulation on database you just have to follow the MVC method .
VIEW => CONTROLLER => MODEL => CONTROLLER => VIEW
like #Brian Ramsey did . check out the guidelines of codeigniter
https://www.codeigniter.com/user_guide/
Error
Not able to pass the value from this application to other website.
View
In this view using action i have called the controller function. If the user selects Pay-Me then value 1 will be passed to controller function.
<form id="formMuktinath" method="post" action="<?php echo base_url().'index.php/booking/bookManakamana'?>">
<div class="form-group">
<label for="name" class="col-sm-3 col-lg-offset-2 control-label">Payment From </label>
<div class="col-sm-4">
<select class="select form-control" name="manakamana[payment_from]">
<option value="1" selected>Pay-Me</option>
<option value="2">BIL</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-5">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
Controller
If 1 is selected then it calls payme website. Then there redirect function using $data does not pass amt value to payme website.
public function bookManakamana(){
if ($data = $this->input->post('manakamana')) {
$data['created_on'] = date('Y-m-d H:i:s');
if ($data['payment_from'] == '1') {
$data['amt'] = '100';
redirect('http://dev.payme.com/pay/main',$data);
}
if ($data['payment_from'] == '2') {
echo 'bli';
exit;
}
redirect('booking/index');
} else {
$this->load->view('index');
}
}
if you want to pass values in link as get variable
www.somewebsite.com/?var='value'
but if you want to send variable as post you need to use curl
Im trying to insert multiple checkboxes but cant get their values in codeigniter 2
this is my code in View
<!-- Multiple Checkboxes (inline) -->
<div class="form-group">
<div class="col-md-4">
<label class="checkbox-inline" for="checkboxes-0">
<input type="checkbox" name="checkboxes[]" id="checkboxes-0" value="22">
Пентхаус
</label>
<br>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="cena" name="cena[]" type="text" placeholder="Въведи цена" class="form-control input-md">
</div>
</div>
<label class="checkbox-inline" for="checkboxes-1">
<input type="checkbox" name="checkboxes[]" id="checkboxes-1" value="21">
Гараж/Паркомясто
</label>
<br>
<!-- Text input-->
<div class="form-group">
<div class="col-md-8">
<input id="cena" name="cena[]" type="text" placeholder="Въведи цена" class="form-control input-md">
</div>
</div>
This is my Model:
public function InsertCheckbox() {
$property_typesRequest = $this->input->post('checkboxes');
foreach($property_typesRequest as $value){
$this->db->insert_batch('property_type_details', $property_typesRequest);
}
}
in Controller i just use this:
$this->estate_m->InsertCheckbox();
And this going insert 0 in database, when i var_dump $property_typesRequest theres shows bool(false). I cant get values of checkboxes...
EDIT...
I have try to edit my code but still no result:
public function edit()/*this is controller */
{
$data=array('column_name'=>$this->input->post('checkboxes');
$result=$this->estate_m->InsertCheckbox($data);
if($result==true)
{
echo "Success";
}
else
{
echo "Fail";
}
}
public function InsertCheckbox($data) /*this is Model */
{
$this->db->insert('property_type_details', $data);
return ($this->db->affected_rows() != 1 ) ? false : true;
}
With this edited code always gives me Succes
Form submitted values should be in multi dimension array
To achieve that your form inputs should be in multi dimension.
For insert_batch() function, the array should be in multi dimension.
In array every key must be field names in db table and value must be the form input value.
So change the form structure like the below array.
array(
array(
'checkboxes' => 'checkboxe value' ,
'cena' => 'cena values'
),
array(
'checkboxes' => 'checkboxe value' ,
'cena' => 'cena values'
)
);
Form inputs should be like below:
<input name="data[1][checkbox_columnname]" type="checkbox" value="21">Пентхаус
<input name="data[1][textbox_columnname]" type="text">
<input name="data[2][checkbox_columnname]" type="checkbox" value="22">Гараж/Паркомясто
<input name="data[2][textbox_columnname]" type="text">
And the model should not have foreach loop.
Simply pass the data as below.
$data=$this->input->post('data');
$this->db->insert_batch('mytable', $data);
Please use this code in model.
public function InsertCheckbox() {
$property_typesRequest = $this->input->post('checkboxes');
foreach($property_typesRequest as $value){
$data['columnename'] = $value;
$this->db->insert('tablename', $data);
}
}
Hope it inserts into the database
Thank you