I have a for loop inserting data into my table, works well.
Problem is each loop I wish for it to start a new row, but it starts a new table. any ideas how to fix this?
<?php if (isset($records)) : foreach ($records as $row) : ?>
<div id="mobile-content">
<table class="table table-hover">
<thead>
<tr>
<th>Account Name</th>
<th>Balance</th>
<th>Start Date</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $row->bank_name; ?></td>
</tr>
<tr>
<td><?php echo $row->bank_balance; ?></td>
</tr>
<tr>
<td><?php echo $row->bank_start_date; ?></td>
</tr>
</tbody>
</table>
</div>
<?php endforeach; ?>
You should change the code to loop inside the table body, not in the whole table code:
<div id="mobile-content">
<table class="table table-hover">
<thead>
<tr>
<th>Account Name</th>
<th>Balance</th>
<th>Start Date</th>
</tr>
</thead>
<tbody>
<?php if (isset($records)) : foreach ($records as $row) : ?>
<tr>
<td><?php echo $row->bank_name; ?></td>
<td><?php echo $row->bank_balance; ?></td>
<td><?php echo $row->bank_start_date; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
Note: I've also remove extra <tr> because you need one row for the three cells.
I hope that helps :D
Related
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);
I'm trying to delete data from my database
Here's my code:
VIEW
<table border="1" class="table">
<tr>
<th>No</th>
<th>Nama Depan</th>
<th>Nama Belakang</th>
<th>TTL</th>
<th>Email</th>
<th>Keterangan</th>
</tr>
<?php
$i = 0;
foreach ($dataMember as $result) { ?>
<tr>
<td><?php echo ($i+1); ?></td>
<td><?php echo $result['namaDepan'];?></td>
<td><?php echo $result['namaBelakang']; ?></td>
<td><?php echo $result['TTL']; ?></td>
<td><?php echo $result['email']; ?></td>
<td>
<button>Delete</button>
</td>
</tr>
<?php $i++; } ?>
</table>
MODEL
public function Hapusdata($id){
$this->db->where('email', $id);
$this->db->delete('daftar');
}
Controller
public function hapusMember()
{
$this->load->model('Member');
$this->load->helper('url');
$id = $this->uri->segment(3);
$this->Member->Hapusdata($id);
redirect (site_url('Belajarberhadiah/halaman_admin'));
}
and the problem is i get
Severity: Notice
Message: Trying to get property of non-object
Filename: views/halaman_dMember.php
Line Number: 105
What should i do?
Please write href for delete tag as below:
delete
Also be sure that the column[email] you have used for where condition in controller is the correct one. Because column name is "email" in where condition and you are passing an integer value.
i am new to the programming.i have list of customer in table.i want to make the individual profile page for each customer with their database credentials.So how can i do it to make name clickable so their profile page will open (in codeigniter).this is my table....
<table>
<thead>
<tr>
<th scope="col">S/N</th>
<th scope="col">Customer Name</th>
<th scope="col">Customer Email</th>
<th scope="col">Customer Country</th>
<th scope="col">Customer City</th>
<th scope="col">Customer Address</th>
<th scope="col">Customer Contact</th>
<th scope="col">Customer Image</th>
<th scope="col">Modify</th>
</tr>
</thead>
<tbody>
<?php $i = 1;?>
<?php if($customer->num_rows()>0):?>
<?php foreach($customer->result() as $rows):?>
<tr>
<td><?php echo $i;?></td>
<td><a href="<?php base_url();?>admin/customer/profile"<?php echo $rows->customer_name;?><a></td>
<td><?php echo $rows->customer_email;?></td>
<td><?php echo $rows->customer_country;?></td>
<td><?php echo $rows->customer_city;?></td>
<td><?php echo $rows->customer_address;?></td>
<td><?php echo $rows->customer_contact;?></td>
<td><img id="img" src="<?php echo base_url();?>customer/<?php echo $rows->customer_image;?>" width="30px" height="30px"/></td>
<td>
</td>
</tr>
<?php $i++;?>
<?php endforeach;?>
<?php endif;?>
</tbody>
</table>
In my application, i have upload image and fill some fields. These values and upload image path also to be saved in database. I don't know to how to retrieve image from folder. My code is,
The Controller part is
function getdatatableajax()
{
$this->load->library('datatables');
$this->datatables
->select("products.id as id, pathinfo, products.name as pname, price, measurement, tax_rates.name")// measurement,tax_rates.name
->from("products")
->join('tax_rates', 'tax_rates.id=products.tax_rate', 'left')
->group_by('products.id')
->add_column("Actions",
"<center>
<div class='btn-group'>
<a class=\"tip btn btn-primary btn-xs\" title='".$this->lang->line("edit_product")."' href='index.php?module=products&view=edit&id=$1'>
<i class=\"fa fa-edit\"></i></a>
<a class=\"tip btn btn-danger btn-xs\" title='".$this->lang->line("delete_product")."' href='index.php?module=products&view=delete&id=$1' onClick=\"return confirm('". $this->lang->line('alert_x_product') ."')\">
<i class=\"fa fa-trash-o\"></i></a>
</div></center>", "id")
->unset_column('id');
echo $this->datatables->generate();
}
The model part is
public function getAllProducts()
{
$q = $this->db->get('products');
if($q->num_rows() > 0) {
foreach (($q->result()) as $row) {
$data[] = $row;
}
return $data;
}
}
The View part is
<table id="fileData" cellpadding=0 cellspacing=10 class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th><?php echo $this->lang->line("Image"); ?></th>
<th><?php echo $this->lang->line("name"); ?></th>
<th><?php echo $this->lang->line("price"); ?></th>
<th><?php echo $this->lang->line("Measurement"); ?></th>
<th><?php echo $this->lang->line("tax_rate"); ?></th>
<th style="width:45px;"><?php echo $this->lang->line("actions"); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7" class="dataTables_empty"><?php echo $this->lang->line('loading_data_from_server'); ?></td>
</tr>
</tbody>
<tfoot>
<tr>
<th><?php echo $this->lang->line("Image"); ?></th>
<th><?php echo $this->lang->line("name"); ?></th>
<th><?php echo $this->lang->line("price"); ?></th>
<th><?php echo $this->lang->line("Measurement"); ?></th>
<th><?php echo $this->lang->line("tax_rate"); ?></th>
<th style="width:45px;"><?php echo $this->lang->line("actions"); ?></th>
</tr>
</tfoot>
</table>
From where are add image retrieval code.?
Use This :-
<img src="<?php echo base_url('images/1.jpg'); ?>" />
Check this Post for more details
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