I have created a listbox as follows
echo "<select name="listbox1" multiple>";
echo "<option value="0">-Select-</option>";
foreach ($Details as $Id => $Name) {
echo "<option value="$Id">$Name</option>";
}
echo "</select>";
Now I want to retrieve the values
I try these
$retrievelist['listbox1']= $this->input->post('listbox1');
var_dump($retrievelist);
Which shows only first item from the selected items. thanks in advance
Change this echo "<select name="listbox1" multiple>"; to echo "<select name="listbox1[]" multiple>";
Related
Have displayed data from database using bootstrap card. All these cards have Read more buttons. Once click on the Read More the modal should fetch that specific row details and display.
The view is as shown below
The codes are mentioned below:
Code for View using card
<div class="row clearfix">
<?php
$query = $this->db->query("SELECT * FROM services_offered LIMIT 15");
foreach ($query->result() as $row) {
echo "<div class='col-lg-4 bottommargin-sm'>";
echo "<div class='feature-box media-box fbox-bg'>";
echo "<div class='fbox-media'>";
echo "<a href='#'><img src='$row->swo_images' alt='Featured Box Image' style='height:250px; width:450px;'></a></div>";
echo "<div class='fbox-content fbox-content-lg'>";
$string = $row->swo_brief_intro;
$string = word_limiter($string, 15);
echo "<h3 class='nott ls0 font-weight-semibold'>$row->swo_image_heading<span class='subtitle font-secondary font-weight-light ls0'>$string</span></h3>";
echo "<a href='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#whatwedo'>Read More</a>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
Code for modal that should load:
<?php
$query = $this->db->query("SELECT * FROM services_offered");
foreach ($query->result() as $row) {
echo "<div class='modal fade' id='whatwedo' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
echo "<div class='modal-dialog' >";
echo "<div class='modal-content'>";
echo "<div class='modal-header'>";
echo "<h5 class='modal-title' id='exampleModalLabel'>$row->swo_image_heading</h5>";
echo "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>";
echo " <span aria-hidden='true'>×</span>";
echo "</button>";
echo "</div>";
echo "<div class='modal-body'>";
echo "..";
echo "</div>";
echo "<div class='modal-footer'>";
echo "<button type='button' class='btn btn-secondary' data-dismiss='modal'>Close</button>";
echo "<button type='button' class='btn btn-primary'>Save changes</button>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
?>
Code for controllers
public function fetchDetails($id)
{
$this->db->where('id',$id);
$query = $this->db->query("SELECT * FROM services_offered");
return $query->result();
}
You should give the modal different ID each modal or services, ID must unique for each services.
give id for the button
echo "<a href='fetchDetails' class='button-link border-0 color btn-edit' data-toggle='modal' data-target='#idmodal'>Read More</a>";
and give the modal also the same id
echo "<div class='modal fade' id='idmodal' tabindex='-1' aria-labelledby='exampleModalLabel' aria-hidden='true'>";
you can use services id in your database or give it a unique name make sure the button and the modal have the same id.
I want to display all records from database to my view page. Having a table customers, how can I display all records of this table?
Here is my customer_model.php file..
function all_customss()
{
$query=$this->db->query("select * from customers");
return $query->result();
}
Here are my controller.php file...
function viewpage()
{
$result['data'] = $this->customer_model->all_customss();
$this->load->view('models_view', $result);
}
And here is the link which will display all records after click...
<div class="col-md-12 col-sm-12 text-center"><a class="btn btn-default hvr-bounce-to-right" href="<?php echo site_url('/viewpage/');?>" role="button"><?php echo $this->lang->line('see_more'); ?></a>
and here is my view file...page_view.php
tr><td><?php
$i=1;
foreach($data as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row->firstname."</td>";
echo "<td>".$row->lastname."</td>";
echo "<td>".$row->email."</td>";
echo "</tr>";
$i++;
}
?></td></tr>
You must put the name of your contoller before the name of your function like bellow:
<?php echo site_url('name_of_controoler/viewpage/');?>
function all_customss()
{
$query=$this->db->query("select * from customers");
return $query;
}
tr><td><?php
$i=1;
foreach($data->result () as $row)
{
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$row->firstname."</td>";
echo "<td>".$row->lastname."</td>";
echo "<td>".$row->email."</td>";
echo "</tr>";
$i++;
}
I have modified your code. You should retrieve an array from a model. But it in your case you have already extracted the result in the model. And take a look in the view. I have modified your foreach parameter
This is request_report function in my report_model how can code tabular data in my view passed by controller
function request_report($from, $to, $member_filter )
{
$this->db->select('requests.request_id,items.item_type,items.quantity,items.item_unit,items.item_name, requests.item_id, requests.quantity_requested, requests.quantity_delivered, requests.purpose');
$this->db->from('requests', 'items');
$this->db->join('items', 'items.item_id = requests.item_id');
$this->db->where('created_time >=', $from);
$this->db->where('created_time <=', $to);
if ($member_filter != 'null') $this->db->where('created_by', $member_filter);
$query = $this->db->get();
if ($query->num_rows() > 0 ) {
echo '<table id="requests" class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Category</th>
<th>Items</th>
<th>Quantity Requested</th>
<th>Quantity Available</th>
<th>Quantity Delivered</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>';
foreach ($query->result() as $row) {
echo '<tr>';
echo '<td>';
echo $row->request_id;
echo '</td>';
echo '<td>';
echo $this->get_item_type_name($row->item_type);
echo '</td>';
echo '<td>';
echo $row->item_name;
echo '</td>';
echo '<td>';
echo $row->quantity . " " . $this->get_unit_measurement($row->item_unit);
echo '</td>';
echo '<td>';
echo $row->quantity_requested . " " . $this->get_unit_measurement($row->item_unit);
echo '</td>';
echo '<td>';
echo $row->quantity_delivered . " " . $this->get_unit_measurement($row->item_unit);
echo '</td>';
echo '<td>';
echo $row->purpose;
echo '</td>';
echo '</tr>';
}
echo '</tbody>
</table>';
}
else{
return '<h4 style="text-align: center; padding: 37px;"> No Matching Requests Found </h4>';
}
}
and this is my view
<div class="col-sm-12">
<?php echo $this->report_model->request_report($from, $to, $member_filter)>
</div>
my question is how can pass data from model to view through controller, not just calling model directly in view, and i need the tabular data in model to be in view, am looking for any help thanks!!
my question is how can pass data from model to view through
controller, not just calling model directly in view, and i need the
tabular data in model to be in view, am looking for any help thanks!!
In your controller say method is index()
<?php
class Site extends CI_Controller{
function index()
{
// this you can also put in __construct
// if you want to share same model across other methods
$this->load->model('report_model');
// And call your model function like below
$data = $this->report_model->request_report('2015-12-10', '2016-03-10', 'some_user');
// load view
$this->load->view('bootstrap_view',array('model_output' => $data));
}
}
and in your view, say bootstrap_view.php
<div class="col-sm-12">
<?php echo $model_output;>
</div>
Also note you can make use of table class in codeigniter, where you can set template of your interest, for more details follow below link
https://www.codeigniter.com/user_guide/libraries/table.html
i have a form that insert loop data. the problem is even i don't insert new data on my form, my database still adding a new one.i can add more one data in same data, but when create new data after first one,get me twice data with empty value.
here is my code
Controller
$doc_number = $_POST['doc_number'];
$closedby = $_POST['closedby'];
$reasonclose = $_POST['reasonclose'];
$description = $_POST['description'];
for($i=0;$i<count($closedby);$i++) {
$solved = array(
'DOC_NUMBER' => $doc_number,
'LOB' => $closedby,
'REASON' => $reasonclose,
'DESCRIPTION' => $description,
'CREATE_DATE' => $dateop,
'ID_SOLVED' => ++$num
);
$this->db->insert('NEWS_EVENT_SOLVED_TAB',$solved);
var_dump($solved);
}
VIEW
<div class="controls" style="margin-left: 70px;">
<input id="idf" type="hidden" value="<?php echo $num;?>" />
<input id="idf" type="hidden" value="1" />
<div id="divSolved"></div>
<button type="button" onclick="addLob(); return false;">Add LOB</button>
</div>
JAVASCRIPT
function addLob() {
var idf = $("#idf").val();
var stre = "<p id='srow" + idf +"'>"+
"<select id='closedby_"+idf+"' name='closedby[]' class='form-control span3'>"+
"<option value=''>Choose One LOB</option>"+
"<option value='alkes'>Alkes</option>"+
"<option value='bd'>BD</option>"+
"<option value='cosmetic'>Cosmetic</option>"+
"<option value='feed'>Feed</option>"+
"<option value='food'>Food</option>"+
"<option value='import'>Import</option>"+
"<option value='logistic'>Logistic</option>"+
"<option value='pharma'>Pharma</option>"+
"<option value='purchasing'>Purchasing</option>"+
"<option value='qa'>QA</option>"+
"</select>"+
"<select id='reasonclose_"+idf+"' name='reasonclose' class='form-control span3'>"+
"<option value=''>Choose One Reason</option>"+
"<option value='Claim Insurance'>Claim Insurance</option>"+
"<option value='Claim Principal'>Claim Principal</option>"+
"<option value='Claim Transporter'>Claim Transporter</option>"+
"<option value='Sample'>Sample</option>"+
"<option value='Sold To Customer'>Sold To Customer</option>"+
"</select>"+
"<textarea rows='2' id='description_"+idf+"' name='description' placeholder='Keterangan'/>"+
"<a href='#' style='color:#3399FD;' onclick='hapusElemen(\"#srow" + idf + "\"); return false;'><img alt='' src='<?php echo themeUrl(); ?>images/delete.png'></a>"+
"</p>";
$("#divSolved").append(stre);
idf++;
$("#idf").val(idf);
}
function hapusElemen(idf) {
$(idf).remove();
}
function confirm(){
var isi = '<div align="" class="text-">Please wait while processing...<br /><img alt="" src="<?php echo themeUrl(); ?>img/ajax_loader.gif" align=""></div>';
$('.modal-body').html(isi);
var modalWidth = 300;
var left = (screen.availWidth - (modalWidth * 2));
$('button.close').hide();
$('#myModal').css({'width':modalWidth+'px','left':left+'px'}).modal({backdrop:'static',keyboard:false,show:true});
var hotdata = $('#productclose').handsontable('getInstance');
hstable = JSON.stringify({'data':hotdata.getData()});
//alert(lob);
for(var i=1; i<$('#idf').val(); i++) {
$.post('<?php echo base_url('report/news_event/confirmed'); ?>',{
doc_number : $('#id_number').val(),
closedby : $('#closedby_'+i).val(),
reasonclose : $('#reasonclose_'+i).val(),
description : $('#description_'+i).val(),
itemdata : hstable
//datenumber : $('#reminder_date').val()
},function() {
//alert($('#closedby').val());
//location.reload();
});
}
}
The issue you've got is that when you submit, even if there's nothing added, is that there will still be one $_POST['closedby'] record, but the value might be blank.
In the for loop, you should check to see if $_POST['closedby'] is empty/blank or generally the default for the options. If it is, then don't do the insert. Something like:
if (!empty($_POST['closedby'][$i])
{
// insert code
}
As a side note, you should use models to interact with your database, and have the controller call functions in the model.
The code below is the display of search result of my project. The code below will display more than 1 row of result which I will put a link to every $value['name'] to proceed to the next page. I need to get which link is clicked and I need to get the $value['name'] which corresponds to the link clicked. Can someone help me please.
<div id="searchBox">
<?php
foreach( $row as $value ) // VALUE IS A ROW
{?>
<?php echo " Name: ";
?> <a href='<?php echo base_url()."main/moreinfo" ?>'><?php echo $value['name']; ? ></a>
<?php
echo '<p>';
echo " Type: ";
echo $value['type'];
echo '<p>';
echo "________________________________________________________________________";
echo '<p>';
}
?>
</div>
You achieve this adding an id $value['id'] to your <a href>. Then you are able to query more info in your controller, after the link was clicked:
<div id="searchBox">
<?php
foreach( $row as $value ) {
$url=base_url( "main/moreinfo/".$value['id'] );
echo 'Name: ';
echo '<a href='.$url.'>'.$value['name'].'</a>';
echo '<p>';
echo ' Type: ';
echo $value['type'];
echo '<p>';
echo '____________________________________________________________';
echo '<p>';
}
?>
</div>