Adding student in only specific class list using codeigniter - codeigniter

I have a problem in viewing only a class list that I choose and add student but when I select other class it will also appear/view that I select in previous class
here I select the class that I select
Here is the class page that I select and then I add student
but when I choose another class it will also appear the student
here is my controller:
public function viewspecificclass($id)
{
if($this->session->userdata('logged_in'))
{
$this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
$this->output->set_header('Pragma: no-cache');
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$row=$this->model_adminlogin->getonerowclass($id);
$data['r']=$row;
$data['classid'] = $id;
$this->load->view('individualviewclass',$data);
} else{
redirect('welcome', 'refresh');
}
if((!isset($session_data) || $session_data !=TRUE)) {
redirect('welcome', 'refresh');
}
}
public function addstudentnow($classid, $studentid){
$data= array(
'ClassId'=>$classid,
'Id'=> $studentid
);
$this->db->insert('enroll',$data);
$this->session->set_flashdata('category_success', 'Successfully Add!');
redirect('enrollment/viewspecificclass ');
}
here is my model:
function statusofenrollment(){
$this->db->select('*');
$this->db->from('studentinformation');
$this->db->join('statusofenrollment', 'statusofenrollment.Id = studentinformation.Id', 'left');
$query = $this->db->get();
return $query->result();
}
function studentinclasslist(){
$this->db->select('*');
$this->db->from('statusofenrollment');
$this->db->join('studentinformation', 'studentinformation.Id = statusofenrollment.Id', 'right');
$this->db->join('enroll', 'enroll.Id = studentinformation.Id', 'right');
$query = $this->db->get();
return $query->result();
}
here is the view:
<div class="z table-responsive">
<table class=" table table-striped ">
<thead>
<tr>
<th class="text-center">LRN</th>
<th class="text-center">First name</th>
<th class="text-center"> Middle name</th>
<th class="text-center">Last name</th>
<th class="text-center">Gender</th>
<th class="text-center">Status of Enrollment</th>
<th class="text-center"> </th>
</tr>
</thead>
<?php
foreach($this->model_adminlogin->studentinclasslist() as $row){
?>
<tr>
<td class="text-capitalize text-center"><?php echo $row->Idnumber ?></td>
<td class="text-capitalize text-center"><?php echo $row -> Firstname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Middlename ?></td>
<td class="text-capitalize text-center"><?php echo $row->Lastname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Sex ?></td>
<td class="text-capitalize text-center"><?php echo $row->Statusofenrollment ?></td>
<td class="text-capitalize text-center">
</td>
</tr>
<?php
}
?>
</table>
</div>
<div id="myModalpick" class="modal fade" role="dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title text-center">Student Status</h4>
</div>
<div class="modal-body">
<div class="z table-responsive">
<table class=" table table-striped ">
<thead>
<tr>
<th class="text-center">LRN</th>
<th class="text-center">First name</th>
<th class="text-center"> Middle name</th>
<th class="text-center">Last name</th>
<th class="text-center">Gender</th>
<th class="text-center">Status of Enrollment</th>
<th class="text-center"> </th>
</tr>
</thead>
<?php
foreach($this->model_adminlogin->statusofenrollment() as $row){
?>
<tr>
<td class="text-capitalize text-center"><?php echo $row->Idnumber ?></td>
<td class="text-capitalize text-center"><?php echo $row -> Firstname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Middlename ?></td>
<td class="text-capitalize text-center"><?php echo $row->Lastname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Sex ?></td>
<td class="text-capitalize text-center"><?php echo $row->Statusofenrollment ?></td>
<td class="text-capitalize text-center">
Add To Class List
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" >Ok</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>

because of the fact that your code is totally unorganized it makes hard to help you - but i'll give it a shot
first of all in your models Function studenClassList you've to pass an id from the specific class because other wise you'll get on any request the students of all of your classes - change your model like this
function studentinclasslist($classId){
$query = $this->db
->select('studentinformation.*')
->from('statusofenrollment')
->join('studentinformation', 'studentinformation.Id = statusofenrollment.Id', 'right')
->join('enroll', 'enroll.Id = studentinformation.Id', 'right')
->where("class.Id",$classId)
->get();
return $query->result();
}
be aware that you have to change in the where construct the actual class.Id field because i wasn't able to see where it is
and after that in your view simply pass the ID to your model function
foreach($this->model_adminlogin->studentinclasslist($classId) as $row){
but in any case i must say, in my opinion it isn't a good idea in CI to use a model in your view because the controller should pass the prepared model data to the view

Related

Phpspreadsheet import excell when an empty date format

Good day evening my goal here is when the excel has an empty date it will display in the data table an empty output, but it displays 01/01/1970 after I import excel empty data i had use strtotime format
empty data in my excell
Display in my datable
Here is my code below on displaying in the datable
<thead>
<tr>
<th class="text-center align-middle">Action</th>
<th class="text-center align-middle ">Last Name</th>
<th class="text-center align-middle ">First Name</th>
<th class="text-center align-middle ">Middle Name</th>
<th class="text-center align-middle ">Zone</th>
<th class="text-center align-middle ">Birth Day</th>
<th class="text-center align-middle ">Age</th>
<th class="text-center align-middle">Service Give</th>
<th class="text-center align-middle ">LMP</th>
<th class="text-center align-middle ">EDC</th>
<th class="text-center align-middle ">GPA</th>
<th class="text-center align-middle ">REMARKS</th>
<th class="text-center align-middle ">Teenage Pregnancy</th>
</tr>
</thead>
<tbody>
<?php
if($records){
foreach ($records as $record):
?>
<tr>
<td class="text-center align-middle">
<a href="<?php echo base_url('dashboard/editteen/'.$record->id); ?>" class="btn btn-primary "title="Edit Record">
<i class="fas fa-edit"></i>
</a>
</td>
<td class="text-center align-middle"><?php echo $record->lastname;?></td>
<td class="text-center align-middle"><?php echo $record->firstname;?></td>
<td class="text-center align-middle"><?php echo $record->middlename;?></td>
<td class="text-center align-middle"><?php echo $record->zone;?></td>
<td class="text-center align-middle">
<?php echo !empty($record->bday) ? date('m/d/Y', strtotime($record->bday)) : '';?>
</td>
<td class="text-center align-middle"><?php echo $record->age;?></td>
<td class="text-center align-middle"><?php echo $record->servicegive;?></td>
<td class="text-center align-middle">
<?php echo !empty($record->lmp) ? date('m/d/Y', strtotime($record->lmp)) : '';?>
</td>
<td class="text-center align-middle">
<?php echo !empty($record->edc) ? date('m/d/Y', strtotime($record->edc)) : '';?>
</td>
<td class="text-center align-middle"><?php echo $record->gpa;?></td>
<td class="text-center align-middle"><?php echo $record->remarks;?></td>
<td class="text-center align-middle"><?php echo $record->teenagepregnancy;?></td>
</tr>
down here is my code in importing
For loop in
if($sheetcount>1)
{
$data=array();
for ($i=1; $i < $sheetcount; $i++) {
$lastname=$sheetdata[$i][1];
$firstname=$sheetdata[$i][2];
$middlename=$sheetdata[$i][3];
$zone=$sheetdata[$i][4];
$bday=date('y-m-d',strtotime($sheetdata[$i][5]));
$age=$sheetdata[$i][6];
$servicegive=$sheetdata[$i][7];
$lmp=date('y-m-d',strtotime($sheetdata[$i][8]));
$edc=date('y-m-d',strtotime($sheetdata[$i][9]));
$gpa=$sheetdata[$i][10];
$remarks=$sheetdata[$i][11];
$teenagepregnancy=$sheetdata[$i][12];
set of data array
$data[]=array(
'lastname'=>$lastname,
'firstname'=>$firstname,
'middlename'=>$middlename,
'zone'=>$zone,
'bday'=>$bday,
'age'=>$age,
'servicegive'=>$servicegive,
'lmp'=>$lmp,
'edc'=>$edc,
'gpa'=>$gpa,
'remarks'=>$remarks,
'teenagepregnancy'=>$teenagepregnancy,
);
}
$inserdata=$this->m->insert_batch_teen($data);
if($inserdata)
{
$this->session->set_flashdata('message','<div class="alert alert-success">Successfully Added.</div>');
redirect('dashboard/importteen');
} else {
$this->session->set_flashdata('message','<div class="alert alert-danger">Data Not uploaded. Please Try Again.</div>');
redirect('dashboard/importteen');
}
}
}
Just put it in an IF statement.
$lmp=date('y-m-d',strtotime(''));
When strtotime is empty, it always returns 70-01-01.
Change to:
$lmp=$sheetdata[$i][8] ? date('y-m-d',strtotime($sheetdata[$i][8])) : '';

Paging in codeigniter doesn't work - could not be converted to string

I'm not able to insert the pager function inside the readHunters() method so that the records in my table are not all on the same page (I want to put 10 records per page).
I know that in app->Config->Pager.php there is public $perPage = 10; which helps to define the number of records in the table with pagination.
HunterController.php
public function readHunters()
{
try {
$hunter = new HunterModel();
$data['hunter'] = $hunter->findAll();
$data['pager'] = $this->$hunter->page;
return view('read_hunters', $data);
} catch (\Exception $e) {
exit($e->getMessage());
}
}
read_hunters.php
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Year</th>
<th>Height</th>
<th>Weight</th>
<th>Type hunter</th>
<th>Type nen</th>
<th>Type blood</th>
<th>Date registration</th>
<th>Date upgrade</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($hunter as $hxh): ?>
<tr>
<td><?= $hxh['id_hunter']?></td>
<td><?= $hxh['name_hunter']?></td>
<td><?= $hxh['year_hunter']?></td>
<td><?= $hxh['height_hunter']?> m</td>
<td><?= $hxh['weight_hunter']?> kg</td>
<td><?= $hxh['type_hunter']?></td>
<td><?= $hxh['type_nen']?></td>
<td><?= $hxh['type_blood']?></td>
<td><?= date('d/m/Y H:i:s', strtotime($hxh['date_registration']))?></td>
<td><?= $hxh['date_update'] == $hxh['date_registration'] ? '' : date('d/m/Y H:i:s', strtotime($hxh['date_update'])) ?></td>
<td>
"><i class="fa fa-edit"></i> Update
<i class="fa fa-trash"></i> Delete
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?= $pager->links(); ?>
To provide a paginated list in the app, your controller's method looks like this:
$data = [
'hunter' => $hunter->paginate(10),
'pager' => $hunter->pager,
];
return view('read_hunters', $data);

how to update cart quantity in CodeIgniter?

I want to update the quantity of a shopping cart. I've google it a lot but couldn't do it.
Maximum pages are showing which i don't want. Exactly solution i'm not getting. Hopefully i will get here. Please help me to do it. Here is my view page.
**<table class="table table-hover table-bordered table-striped snipcart-details "> <thead>
<tr>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Delete Cart</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Product Name</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Image</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Price</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Quantity</th>
<th colspan="2" style="color:#FF0033; font-weight:bolder; text-align:center;" >Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->cart->contents() as $items) { ?>
<tr>
<td style="color:#000000; font-weight:bolder; text-align:center;" >
<a href="#" class="remove_cart" title="delete" row_id="<?php echo $items['rowid']; ?>" rel="1">
<i class="fa fa-times fa-2x" style="color:red;" aria-hidden="true"></i> </a></td>
<td style="color:#000000; font-weight:bolder; text-align:center;" ><?php echo $items['name']; ?></td>
<td align="center"><img src="<?php echo base_url('resource/allproduct/'.$items['productImage']);?>" height="50px;" /></td></td>
<td style="color:#000000; font-weight:bolder; text-align:center;"><?php echo $items['price']; ?></td>
<td align="center"><input type="number" name="qty" id="qty" value="<?php echo $items['qty']; ?>"></td>
<td colspan="2" style="color:#000000; font-weight:bolder; text-align:center;">TK <?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php } ?>
</tbody>
<tbody>
<tr>
<th scope="row"> <input type="button" name="submit" value="Update" class="button" /> </th>
<td align="center"> <input type="button" name="submit" value="Continue Shopping" class="button" /></td>
<td colspan="3" class="button" align="center" >
<?php if(!empty($userid)){?>
<input class="button" type="submit" value="Place Order">
<?php } else {?>
<input class="button" type="submit" value="Place Order">
<?php }?>
</td>
<td align="center" style="color:#000000;" > <h4>Grand Total</h4> </td>
<td style="font-size:24px; font-weight:800; color:green;">TK <?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</tbody>
</table>**
And here is controler.
public function index()
{
$data['basicinfo'] = $this->M_cloud->basicall('basic_info');
$where = array('status' => 1);
$data['categoryinfo'] = $this->M_cloud->categoryinfo('item_manage', $where);
$data['rows'] = count($this->cart->contents());
$data['userid'] = $this->session->userdata('user_id');
$data['subcategoryinfo'] = $this->M_cloud->findAll2('sub_category', array('status' => 1));
$data['menuinformation'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 2), 'menuname asc');
$data['menuservice'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 1), 'menuname asc');
$data['socialmedia'] = $this->M_cloud->findAll('social_tbl', 'name asc');
$data['newsinfo'] = $this->M_cloud->findAll('news_table', 'newstitle DESC');
$this->load->view('cartPage', $data);
}
public function buy()
{
$proId = $this->input->post('proId');
$Qty = $this->input->post('Qty');
$prosize = $this->input->post('prosize');
$result = $this->M_cloud->find('product_manage', array('proid' => $proId));
$data2 = array(
'id' => $proId,
'qty' => $Qty,
'name' => $result->proName,
'price' => $result->price,
'prosize' => $prosize,
'productImage' => $result->proimg1,
'product_code' => $result->procode
);
$this->cart->insert($data2);
redirect('cart');
}
public function deleteCartItem() {
$row_id = $this->input->post('row_id');
$data = array(
'rowid' => $row_id,
'qty' => 0
);
$this->cart->update($data);
}
Please help me how to update cart quantity. Thanks in Advance.
To update cart Item :
function updateCartItem(){
$data=array(
'rowid'=>$this->input->post('rowid',TRUE),
'qty'=> $this->input->post('quantity',TRUE)
);
if ($this->cart->update($data)) {
echo "Success";
}else{
echo "Faliure";
}
}
To remove the item from cart :
function deleteCartItem(){
$row_id = $this->input->post('row_id',TRUE);
if ($rowid) {
return $this->cart->remove($rowid);
}
}

Error update row in codeignaitor

i have error when i update row to database.
my problem is not update the row and call me when i upload pic with update the file upload not define in index.
my controller :
public function addedit(){
$events = new events_model();
$prodID = $this->input->post('hID');
$text = $this->input->post('ev_text');
$pic = $this->do_upload('ev_pic');
$submit = $this->input->post('submit');
if($submit){
if(!empty($prodID)){
$this->data['events'] = $events->UpdatePost($prodID, $text , $pic );
$this->data['pagetitle'] = "Show Info";
$this->data['success']= "Update Done";
}else{
$this->data['success'] = "Add Done";
}
$this->data['status'] = "1";
}else{
$this->data['status'] = "0";
$this->data['errors'] = "Error";
}
$this->template->build('admin/events/add',$this->data);
}
and model :
function UpdatePost($prodID, $text , $pic ) {
if ($pic == ""){
$vales = array('ev_id' => $prodID , 'ev_text' => $text);
}else{
$vales = array('ev_id' => $prodID , 'ev_text' => $text , 'ev_pic' => $pic);
}
$query = $this->db->update($this->table_name, $vales) or die (mysql_error());
$result = array();
$result["process"] = "ok";
echo "1";
}
and view :
<div class="widget-body">
<table class="data-table" action="./administrator/categories/delete/"><!-- Table Conversion: See Section E in custom.js -->
<thead>
<tr>
<th class="sorting no-background" rowspan="1" colspan="1" style="width: 35px;"><input type="checkbox" id="checkall" /></th>
<th class="sorting" rowspan="1" colspan="1" style="width: 343px;">Tittle</th>
<th class="sorting" rowspan="1" colspan="1" style="width: 100px;">Date</th>
<th class="sorting no-background" rowspan="1" colspan="1" style="width: 70px;">#</th>
</tr>
</thead>
<tbody>
<?php $ctr = 0; ?>
<?php foreach ($events as $n): ?>
<tr>
<td><input class="checkrow" type="checkbox" value="<?php echo $n->ev_id; ?>" /></td>
<td class=" sorting_1"><?= $n->ev_text; ?></td>
<td class="center"><?= $n->ev_date; ?></td>
<td>
<span>Edit</span>
<span>Del</span>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<div id="table-extra">
<div id="table-action">
<input action="./administrator/<?php echo $this->uri->segment(2)."/deleteitems" ?>" class="btn-theme table-button btn-hover-black DeleteItems" id="submit" type="button" value="Delete" />
</div>
<div class="paginate">
<ul>
<?= $this->pagination->create_links(); ?>
</ul>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
where problem in my code , and i wont to update success.
you don't load models like this $events = new events_model(); in CI, you should do it like this :
$this->load->model('Model_name');
$this->Model_name->function();
ref : http://ellislab.com/codeigniter/user-guide/general/models.html#loading

store session cart to database

Sorry for asking this old questions, and I know that I've read before I ask here, it's can use database for adding more cart without limitation. I already try to use ci_sessions table to store session but still no luck, I only can adding 6 items maximum.
please help me, I looking for some example for this almost two days and result is nothing
EDITED
this is my view
<table id="box-table-a" summary="Employee Pay Sheet">
<thead>
<tr>
<th scope="col">Description</th>
<th scope="col">Price</th>
<th class="centered" scope="col">Options</th>
</tr>
</thead>
<tbody>
<?php foreach ($foto_produk->result() as $key => $value) {?>
<tr>
<td><?php echo $value->description;?></td>
<td><?php echo $value->price;?></td>
<td class="centered"><input type="checkbox" name="produk_foto[]" value="<?php echo $value->id;?>" /></td>
</tr>
<?php }?>
</tbody>
</table>
here's my controller code
if($this->input->post('produk_foto')){
$id_foto = $this->input->post('produk_foto');
foreach ($id_foto as $key => $value) {
$this->db->where('id', $value);
$query = $this->db->get('foto_product');
if($query->num_rows() > 0){
foreach($query->result() as $ids => $rows){
echo $rows->id.'<br />';
$data_produk = array(
'user_data'=> array(
'id' => $rows->id,
'price' => $rows->price,
'name' => $rows->description,
'qty' => $rows->aantal
)
);
$this->cart->insert($data_produk);
}
}
}
}
and this my view code
<?php if(!$this->cart->contents()):?>
<div class="alert-box warning">The regular products are empty.</div>
<div class="clearfix"></div>
<?php else:?>
<hr>
<h4>REGULAR PRODUCTS</h4>
<div class="order_detail" id="Display">
<table>
<thead>
<tr>
<th>DESCRIPTION</th>
<th>QUANTITY</th>
<th>PRICE PER ITEM(S)</th>
<th>TOTAL</th>
<th>REMOVE</th>
</tr>
</thead>
<tbody>
<?php foreach($this->cart->contents() as $rows):?>
<tr>
<td style="font-weight:bold;"><?php echo $rows['name'];?></td>
<td>
<?php echo form_open(current_url());?>
<input type="text" size="3" name="quantity" value="<?php echo $rows['qty'];?>" />
<input type="hidden" size="3" name="rowid" value="<?php echo $rows['rowid'];?>" />
<input type="submit" name="update" value="Update" />
<?php echo form_close();?>
</td>
<td><?php echo $rows['price'];?></td>
<td><?php echo $this->cart->format_number($rows['subtotal']);?></td>
<td>delete</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan="3">Total Products</td>
<td colspan="3">€ <?php echo $this->cart->format_number($this->cart->total());?></td>
</tr>
<tr>
<td colspan="3">Total Shipping</td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="3" style="padding:0;text-align:center;">
<p>TOTAL :</p>
<span class="tot">€ <?php echo $this->cart->format_number($this->cart->total());?></span>
</td>
</tr>
</tfoot>
</table>
</div>
<?php endif;?>
with this code I want to insert using checkbox with array, and I have more than 6 checkbox
thank you in advance
Ok it's solved by my self..
I don't know that in the name of product there are special characters..
and shame of me..
but thank you anyway

Resources