I tried to make responsive image for all image thumbnail from my database.
the thumbnail is showing, but when I clicked it, all of it display the first image only. why this is happening?
here is a few line code from view file
<div data-toggle="modal" data-target="#myModal">
<table id="dynamic-table" method="post" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>No</th>
<th>Nama Lengkap</th>
<th>Tanggal Mulai</th>
<th>Tanggal Akhir</th>
<th>Alasan</th>
<th>File</th>
<th>Nopeg</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($hasil->result() as $row) { ?>
<tr>
<td>
<?php echo $row->no ?></td>
<td>
<?php echo $row->nama ?></td>
<td>
<?php echo $row->tglm ?></td>
<td>
<?php echo $row->tgla ?></td>
<td>
<?php echo $row->alasan ?></td>
<td>
<img src="<?php echo base_url().'uploads/'.$row->file ?>" height="75">
<div id="myModal" class="modal fade" role="dialog" data-backdrop="static" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<img src="<?php echo base_url().'uploads/'.$row->file ?>" class="img-responsive">
</div>
</div>
</div>
</div>
</td>
<td>
<?php echo $row->nopeg; ?></td>
<td>
<button type="button" class="btn btn-pink btn-sm">Terima</button>
<button type="button" class="btn btn-info btn-sm">Tolak</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
$('#myModal').on('show.bs.modal', function(e) {
var image = $(e.relatedTarget).attr('src');
$(".img-responsive").attr("src", image);
});
});
</script>
</div>
here is a code from model
<? php
class Model_data_cuti extends CI_Model {
public
function getdata() {
$hasil = $this - > db - > query("SELECT * FROM form");
return $hasil;
}
public
function create($data_form) {
$this - > db - > insert('form', $data_form);
}
public
function find($no) {
$hasil = $this - > db - > where('no', $no) - > limit(1) - > get('form');
if ($hasil - > num_rows() > 0) {
return $hasil - > row();
} else {
return array();
}
}
} ?>
and this is from controller
<? php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Data_cuti extends CI_Controller {
function __construct() {
parent::__construct();
$this - > load - > model('model_data_cuti');
}
public
function index() {
$data['hasil'] = $this - > model_data_cuti - > getdata();
$this - > load - > view('data_cuti_view', $data);
}
} ?>
this is the result page
enter image description here
look at the file column. if i clicke th image, it only display image from first row. when i click others image, it display the first image too.
I see there in your view code, you tried to get the image by
e.relatedTarget for modify your modal.
Mistake :
You do loop the modals, but declare the same id, it was write such as :
<div id="myModal" class="modal fade" role="dialog" data-backdrop="static" aria-labelledby="myModalLabel" aria-hidden="true">
If you inspect the element in your browser you will find that you have a lot of modals with the same id.
Approach Solution :
Just move out the modals from the loop condition, and try to modify it by onclick event listener inside of the true image of yours.
Code Provided ( Untested ) :
<td> <img onclick="photoModal('<?php echo base_url().'uploads/'.$row->file ?>');" src="<?php echo base_url().'uploads/'.$row->file ?>" height="75">
<script>
function photoModal(imgPath){
$('#myModal < div < div < div <img').attr("src",imgPath);
$('#myModal').modal('show');
}
</script>
Explanation
So, while you clicked the image, it will trigger function photoModal() to send the src attribute to the Modal and proccess it to change the src image inside of Modals
I already trick it with some code. My purpose is to make the image larger, so the user can read it.
ps: I already removed the modals.
here is my code in view
<table id="dynamic-table" method="post" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>No</th>
<th>Nama Lengkap</th>
<th>Tanggal Mulai</th>
<th>Tanggal Akhir</th>
<th>Alasan</th>
<th>File</th>
<th>Nopeg</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($hasil->result() as $row) { ?>
<tr>
<td>
<?php echo $row->no ?></td>
<td>
<?php echo $row->nama ?></td>
<td>
<?php echo $row->tglm ?></td>
<td>
<?php echo $row->tgla ?></td>
<td>
<?php echo $row->alasan ?></td>
<td>
<a class="thumbnail" href="<?php echo base_url().'uploads/'.$row->file ?>">
<img src="<?php echo base_url().'uploads/'.$row->file ?>" width="50" height="50">
</a>
</td>
<td>
<?php echo $row->nopeg; ?></td>
<td>
<button type="button" class="btn btn-pink btn-sm">Terima</button>
<button type="button" class="btn btn-info btn-sm">Tolak</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
if you have another way to make the modal working right, just tell me. thanks. ^^,
Related
After reviewing the product I've just approved and on a single product page it shows comments but the rating star is not showing.
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<col width="1" />
<col />
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
I need to show one row per page.
this my contoller class code
public function showcontent($id)
{
$story=storybook::find($id);
$content=storycontent::where('titleid', $story['id'])->paginate(1);
//return $content;
return view('storyBook/viewStory',compact('story','content'));
}
this my view class code
#foreach($content as $content)
<?php $a=null; ?>
<?php $b=null; ?>
<?php $a=$content->file1; ?>
<?php $b=$content->file2; ?>
<table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px">
<tr>
<td style="width: 340px"><img src="/{{$a}}" alt="Mountain View" style="width:330px;height:300px;"></td>
<td style="width: 340px"><img src="/{{$b}}" alt="Mountain View" style="width:330px;height:300px;"></td>
</tr>
</table>
<br>
#endforeach
In here i get only 1st row, rest of the rows not visible..
I do not know how to add pagination.
#foreach($content as $content)
So first of all change the naming of vars for example:
#foreach($content as $entry)
<table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px">
<tr>
<td style="width: 340px"><img src="/{{$entry->file1}}" alt="Mountain View" style="width:330px;height:300px;"></td>
<td style="width: 340px"><img src="/{{$entry->file2}}" alt="Mountain View" style="width:330px;height:300px;"></td>
</tr>
</table>
<br>
#endforeach
$content->links()
As you can see I've added $content->links() after foreach loop. This is the method of Paginator that print out the pagination navigation.
can someone tell me what's wrong with my code? been stuck here for hours... it always says that "DataTables warning: table id=datatable - Requested unknown parameter '1' for row 0."
here's my code:
<table id="datatable" class="table table-bordered table-striped dataTable">
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<?php echo $this->session->flashdata('message'); ?>
<?php $offset = $this->uri->segment(3, 0) + 1; ?>
<?php foreach ($query->result() as $row): ?>
<tr>
<td><?php echo $row->manufacturer_name; ?></td>
<?php echo "<form method='post' action='asset_management/updateForm'>";?>
<input type="hidden" name="manufacturer_id" value="<?php echo $row->manufacturer_id;?>"/>
<?php echo form_open('asset_management/updateForm');
echo form_submit('p_submit', 'Update', "class='btn btn-warning btn-xs'"); ?>
<?php echo form_close(); ?>
</form>
<a class="btn btn-danger btn-xs" onclick="javascript:deleteConfirm('<?php echo site_url('asset_management/deletemanu/' . $row->manufacturer_id); ?>');" deleteConfirm href="#">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></th>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Thank you so much!
no. of table heading may not matches with no. of td in the table.
It shows the mentioned error.
visit https://www.datatables.net/
my code runs well but im getting this error Message: Undefined property: stdClass::$Date and i dont know where this error came from, as far as ive seen my codes are correct. The problem is in my foreach code
here's my controller below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start();
class News_and_events extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->model('admin_model', 'am');
}
public function index(){
if($this->session->userdata('logged_in')){
$this->data['title'] = 'News and Events | Spring Rain Global Consultancy Inc Admin Panel';
$this->data['logout'] = 'Logout';
$session_data = $this->session->userdata('logged_in');
$this->data['id'] = $session_data['id'];
$this->data['username'] = $session_data['username'];
$this->data['allData'] = $this->am->getAllData();
$this->load->view('pages/admin_header', $this->data);
$this->load->view('content/news_and_events', $this->data);
$this->load->view('pages/admin_footer');
}else{
redirect('login', 'refresh');
}
}
}
my model
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Admin_model extends CI_Model{
public function saveData($array){
$this->db->insert('news_and_updates', $array);
}
public function getAllData(){
return $this->db->select(
'news_and_updates.Event',
'news_and_updates.Description',
'news_and_updates.Date'
)
->from('news_and_updates')
->order_by("Date", "desc")
->get()->result_object();
}
}
?>
and my views
<script type="text/javascript">
$(document).ready(function(){
$("#add_another").click(function(){
alert('test');
});
});
</script>
<div class="container" >
<br />
<br />
<br />
<ul id="nav">
<li><h4>Home</h4></li>
<li><h4>News and Events</h4></li>
<li><h4>Activities</h4></li>
</ul>
<div class="starter-template">
<h1>News And Events</h1>
<?php if($this->session->flashdata('add_another')):?>
<div id="add_another" style="float:left;">
<input type="button" value="Add Another" class="btn btn-primary" />
</div>
<?php else: ?>
<form action="<?php echo base_url().'news-and-events/add'?>" method="post">
<?php echo validation_errors('<div class="error">', '</div>');?>
<table class="table-striped">
<tr>
<td>Date: </td>
<td><input type="text" id="datepicker" name="date" value="<?php echo set_value('date');?>" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td >Event: </td>
<td ><input type="text" name="event" value="<?php echo set_value('event');?>" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="20%">Description: </td>
<td><textarea cols="30" rows="5" name="description" ><?php echo set_value('description');?></textarea></td>
</tr>
<tr>
<td width="20%"> </td>
<td><input type="submit" value="Add" class="btn btn-success" /></td>
</tr>
</table>
</form>
<?php endif; ?>
<br />
<br />
<table class="table" >
<tr>
<th>Date</th>
<th width="51%">Event</th>
<th>Description</th>
<th>Options</th>
</tr>
<?php foreach($allData as $x => $allDatas): ?>
<tr>
<td><?php echo $allDatas->Date; ?></td>
<td><?php echo $allDatas->Event; ?></td>
<td></td>
<td></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div><!-- /.container -->
<script>
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#datepicker').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate),
dateFormat: "yy-mm-dd"
});
</script>
in my foreach code the error is this one $allDatas->Date; it says Message: Undefined property: stdClass::$Date
and that's the field name in my table Date
can someone help me figured this out??
any help is much appreciated! thanks! can't find the error
In your model or controller - after the getAllData method is executed:
echo the result of $this->db->last_query()
Manually execute the returned query in your database, then fix your query
As the comments started, The issue is that Date isn't generated from the query, which means something is wrong in that level, not the output itself.
Make sure the query is correct, dump it before you load the view directly from the controller to see what it gets, if it doesn't get a Date, your issue is elsewhere, probably in the query itself.
I am trying to fetch data from my database and when I display it I want to show serial numbers (Just like a list) , example:
**Serial Number** Name Country
1. John USA
2. Srijon UK
I have tried something with PHP Loops, but I couldn't make it work. Would you please kindly help me? please note that by serial numbers I don't mean values retrieved from database.
Thanks in Advance :)
Here's my Model
//Function To Create All Batch List
function batch_list($perPage,$uri) {
$this->db->select('*');
$this->db->from('batch');
$this->db->join('teacher', 'batch.batchinstructor = teacher.teacherid');
$this->db->order_by('batchid','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
//End of Function To Create All Batch List
Here's mY Controller
function index(){
$this->load->library('pagination');
$config['base_url'] = base_url().'batchlist/index';
$config['total_rows'] = $this->db->get('batch')->num_rows();
$config['per_page'] = 20;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('mod_batchlist');
$data['records']= $this->mod_batchlist->batch_list($config['per_page']
,$this->uri->segment(3));
$data['main_content']='view_batchlist';
$this->load->view('includes/template',$data);
}
Here's My View
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $row){ ?>
<tr>
<td><?php echo $row['batchname'];?> </td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?> support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Serial</th>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php $i = $this->uri->segment(3); foreach ($records as $row){ $i++; ?>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['batchname'];?> </td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?> support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
In my case the fourth and fifth parameters where page number and rows per page respectively
ie: example.com/category/page/1/10
first page with 10 rows per page.
so in this case just use this before the loop
$i = $this->uri->segment(4)? (
$this->uri->segment(4) + $this->uri->segment(5)? $this->uri->segment(5):0
)
:0;
and from inside the loop just increment the value of i.
foreach ($result_obj as $key => $value)
{
$i++;
...
}
Try this..work like this..1,2,3,4,5
$i = 0
while($condition)
{
echo '<td>'.$i++.'</td>';
}