Populating Codeigniter Bootstrap Modal from DB via Ajax? - php

I am trying to populate a list of players into a table within a bootstrap modal. Currently I have button that sends the event_id to the controller; the controller then sends a query to the model and I pass the data to a view. However I would like the modal to load within the original view. I am guessing I need some ajax to get this to work however I am having some trouble getting it to work. Hoping someone can point me in the right direction or have another route for me to go.
Here is the code I currently am using.
Controller:
function event_users($event_id)
{
$this->load->model('email_model');
$data['darkteam'] = $this->event_model->dark_team_list($event_id);
$data['lightteam'] = $this->event_model->light_team_list($event_id);
$data['darkgoalie'] = $this->event_model->dark_goalie_list($event_id);
$data['lightgoalie'] = $this->event_model->light_goalie_list($event_id);
$data['event_data'] = $this->email_model->get_location_date($event_id);
$this->load->view('templates/header');
$this->load->view('event/player_list', $data);
}
View:
<td><a href="<?php echo base_url(); ?>event/event_users/<?php echo $e->id; ?>Player List</td>
Modal View (player_list.php):
<script type="text/javascript">
$(window).load(function(){
$('#user_event_modal').modal('show');
});
</script>
<?php foreach ($event_data as $ed): ?>
<?php $location = $ed->location; ?>
<?php $date = $ed->date; ?>
<?php endforeach; ?>
<!--User Event List-->
<div class="modal fade" id="user_event_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="location.href='<?php echo base_url();?>event'"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading"><strong><?php echo $location . " - " . date("l, F jS # g:ia",strtotime($date)); ?></h4></strong>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<table class="table table-striped table-condensed table-bordered table-list events-list-table">
<thead>
<tr>
<strong>Dark Team</strong>
</tr>
</thead>
<tbody>
<?php if (!empty($darkteam)): ?>
<?php foreach ($darkteam as $row): ?>
<tr>
<td><div style="float: left; text-align: left;"><?php echo ($row->first_name) . " " . ($row->last_name); ?></div><div style="float: right; text-align: right;">
<?php if ($this->ion_auth->is_admin()) : ?>
<button onclick="location.href='<?php echo base_url();?>event/switch_team/<?php echo ($row->user_id . "/" . $row->event_id); ?>' " class="btn btn-primary right-block btn-xs" data-dismiss="modal"><i class="fa fa-arrow-right"></i></button>
<?php elseif ($row->user_id == $this->session->userdata('user_id')) :?>
<button onclick="location.href='<?php echo base_url();?>event/switch_team/<?php echo ($row->user_id . "/" . $row->event_id); ?>' " class="btn btn-primary right-block btn-xs" data-dismiss="modal"><i class="fa fa-arrow-right"></i></button>
<?php else: ?>
<?php endif; ?>
</div></td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td class="bg-info" colspan="6">No users currently registered.</td>
</tr>
<?php endif; ?>

Yes, use ajax to empty and then append content to the modal:
<!--replace <a></a> tag with element so jquery can target-->
<td id="update_event">Player List</td>
<!--add an id to the table so ajax can update on success-->
<table id="updateable"class="table table-striped table-condensed table-bordered table-list events-list-table">
Now for the ajax:
//we can use a click event listener
$('#update_event").on("click", "td", function(){
var id = '<?php echo $e->id;?>';
$.ajax({
url: '/event/event_users/'+ id +'',
success: function(results){
$(#updateable).empty(); //first empty table
}) $(#updateable).html(//append data to table)
})

Related

How to fetch data from a variable passed to a modal?

I have a dynamic table with edit and delete button. I was able to passed the variable $parid to modal. However, it's not fetching the data into the modal using the $parid. I cannot figure out what have i missed out. I just want to display the corresponding data using mysql code WHERE parid='$parid'. The value of $parid is passed to the <input type="text" name="parid" id="parid">. Here's my sample code:
<table id="example" class="table table-striped" >
<thead>
<tr>
<th>Param ID</th>
<th>Decription</th>
<th>Code</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
require 'lab/db/dbcon.php';
$query = $con->query("SELECT * FROM param");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['parid'];?></td>
<td><?php echo $row['parnam']; ?></td>
<td><?php echo $row['parcod']; ?></td>
<td>
<!--edit button here-->
<a href="" class="btn btn-danger btn-xs btndel" data-toggle="modal" data-id="<?php echo $row['parid']; ?>" data-target="#delpar"><i class="fa fa-trash"></i>
</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<!-- Start Delete Par Modal -->
<div class="modal fade" id="delpar" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> Are you sure to delete this record?</h5>
</div>
<div class="modal-body">
<input type="text" class="form-control" name="parid" id="parid" disabled>
<table id="example" class="table table-bordered">
<thead>
<tr>
<th>Decription</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<?php
require 'lab/db/dbcon.php';
$parid=isset($_POST['parid']);
$query = $con->query("SELECT * FROM param WHERE parid ='$parid' ");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['parnam']; ?></td>
<td><?php echo $row['parcod']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<div class="modal-footer" style="padding:10px;">
<button type="button" class="btn btn-danger" name="btndel" id="btndel>"> <i class="fa fa-check"></i>
</button>
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-remove"></i></button>
</div>
</div>
</div>
</div>
<!-- End Delete Par Modal -->
<script>
$(document).on("click", ".btndel", function () {
var parid = $(this).data('id');
$(".modal-body #parid").val( parid );
$('#delpar').modal('show');
});
</script>
You have lost track of the scope and timing of your PHP and jQuery code. The jQuery part:
<script>
$(document).on("click", ".btndel", function () {
var parid = $(this).data('id');
$(".modal-body #parid").val( parid );
$('#delpar').modal('show');
});
</script>
runs on the users browser after they have viewed what came from the server. The PHP code inside your "Delete Par Modal" runs on the server before the jQuery even gets to the browser.
In your jQuery you need to add an AJAX call to get the data you need FROM THE SERVER (where your query then runs and returns the data) in real time. Then "on success" the AJAX call should populate the Modal fields.

How do I print only a specific window

I'm have a page where I can view the purchase history of sales
When I click on view full details this is what I get
The problem is when I click print full details this is what I get, I only want to print the window that pops up when I click on view full details
How do I print only the View Full Details window part?
Here's my code:
<!-- History -->
<div class="modal fade" id="detail<?php echo $hrow['salesid']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<center><h4 class="modal-title" id="myModalLabel">Purchase Full Details</h4></center>
</div>
<div class="modal-body">
<?php
$sales=mysqli_query($conn,"select * from sales where salesid='".$hrow['salesid']."'");
$srow=mysqli_fetch_array($sales);
?>
<div class="container-fluid">
<div class="row">x
<div class="col-lg-12">
<p class="pull-right">Date: <?php echo date("F d, Y", strtotime($srow['sales_date'])); ?></p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<label>
<button onclick="printsales()">Print Full details</button>
<script>
function printsales() {
window.print();
}
</script>
</label>
<table width="100%" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Product Name</th>
<th>Price</th>
<th>Purchase Qty</th>
<th>SubTotal</th>
</tr>
</thead>
<tbody>
<?php
$total=0;
$pd=mysqli_query($conn,"select * from sales_detail left join product on product.productid=sales_detail.productid where salesid='".$hrow['salesid']."'");
while($pdrow=mysqli_fetch_array($pd)){
?>
<tr>
<td><?php echo ucwords($pdrow['product_name']); ?></td>
<td align="right"><?php echo number_format($pdrow['product_price'],2); ?></td>
<td><?php echo $pdrow['sales_qty']; ?></td>
<td align="right">
<?php
$subtotal=$pdrow['product_price']*$pdrow['sales_qty'];
echo number_format($subtotal,2);
$total+=$subtotal;
?>
</td>
</tr>
<?php
}
?>
<tr>
<td align="right" colspan="3"><strong>Total</strong></td>
<td align="right"><strong><?php echo number_format($total,2); ?></strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
</div>
</div>
</div>
</div>
You just need to insert simple javascript code to print whole page. And by clicking on Click here to Print you can get print window.
<script type="text/javascript">
function PrintElem(elem,title)
{
Popup($(elem).html(),title);
}
function Popup(data,title)
{
var mywindow = window.open('', '_blank','width=1000,height=700');
mywindow.document.write('<html><head><title>'+title+'</title></head>');
mywindow.document.write('<body onload="window.print()">');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
return true;
}
</script>
Click here to Print
Add an ID to elements you want to hide, for example:
<div id="dontprint"> This will be hidden on print mode </div>
<div> This will be shown on print mode </div>
Then, using CSS hide those elements you don't want to print. Adding a code like this at the end of your code.
<style>
#media print {
div#dontprint{
display: none;
}
}
</style>

Modal Confirm Box in Codeigniter PHP

I have a view in my project(PHP codeigniter), where the user can confirm or remove a particular record from the table of data displayed. When the user chooses to confirm a record, a modal pop up box shows up reassuring the confirmation. Clicking on the Confirm button in this modal will call a controller method to update the DB table appropriately via a consequent model method call. The same applies to the remove functionality in the view. I have implemented and called all the respective methods but it doesn't seem to affect in any way.
Code in context
1.View
<body>
<div class="content" style="background-color: white">
<div class="container-fluid" style="overflow-y: auto">
<legend>Vacancies Applied</legend>
<div>
<form class="form-horizontal" id="viewVacancy">
<?php echo $this->session->flashdata('msgconfirmed');
echo $this->session->flashdata('msgremoved');?>
<table class="table" id="vacancyApplicationTable" >
<thead class="active">
<tr style="background-color: lightblue;color: white" >
<th class="hidden-lg hidden-lg">ID</th>
<th>Company</th>
<th>Job Title</th>
<th>Applied Date</th>
<th>Closing Date</th>
<th>Status</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody >
<?php
if(count($vacanciesApplied)>0) {
foreach ($vacanciesApplied as $row) { ?>
<tr>
<td class="hidden-lg hidden-lg"><a><?php echo $row->vid; ?></a></td>
<td><?php echo $row->onBehalfOf; ?></td>
<td><?php echo $row->jobTitle; ?></td>
<td><?php echo $row->appliedDate; ?></td>
<td><?php echo $row->closingDate; ?></td>
<?php
if ($row->status == "pending")
{
$status = "Pending";
?>
<td><?php echo $status ?></td>
<td></td>
<td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-danger" href="#deleteVacancyApplication">Remove</a></td>
<?php
}
else
{
$status = "Accepted"; ?>
<td class="blink_text"><?php echo $status ?></td>
<td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-info" href="#confirmVacancyStatus">Confirm</a></td>
<td><a data-toggle="modal" data-name="<?php echo $row->vid; ?>" data-id="<?php echo $row->studentId; ?>" title="Add this item" class="open-AddBookDialog btn btn-danger" href="#deleteVacancyApplication">Remove</a></td>
<?php
}
?>
</tr>
<?php }
}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
</body>
<script>
$(function () {
$('#vacancyApplicationTable').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth":true
});
});
</script>
<script>
$(document).on("click", ".open-AddBookDialog", function () {
var studentId = $(this).data('id');
var vid = $(this).data('name');
$(".modal-body #uid").val( studentId );
$(".modal-body #vid").val( vid );
});
</script>
<!-- Modal for confirmVacancyStatus -->
<div class="modal fade" id="confirmVacancyStatus" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false" data-backdrop="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color:lawngreen">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="uid"><i class="glyphicon glyphicon-check"></i> Confirm</h4>
</div>
<div class="modal-body">
<form method="post" id="formConfirm" action="<?php echo base_url() . 'index.php/studentDashboardController/confirmVacancy'?>">
<input type="text" name="vid" id="vid" value="" hidden/>
<div class="form-group">
<p>You got Accepted to follow this vacancy</p>
<p>Do you confirm this?</p>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success pull-right">Confirm</button>
</div>
</div>
</div>
</div>
<!-- Modal for deleteVacancyApplication -->
<div class="modal fade" id="deleteVacancyApplication" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-keyboard="false" data-backdrop="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="background-color:red">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 id="uid"><i class="glyphicon glyphicon-remove"></i> Cancel</h4>
</div>
<div class="modal-body">
<form method="post" id="form" action="<?php echo base_url() . "index.php/studentDashboardController/deleteVacancyRequest"?>">
<input type="text" name="vid" id="vid" value="" hidden/>
<div class="form-group">
<p>Are you sure you want to cancel your application for this vacancy</p>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-danger pull-right">Cancel Application</button>
</div>
</div>
</div>
</div>
2.Controller- studentDashboardController/confirmVacancy
public function confirmVacancy()
{
if (isset($this->session->userdata['logged_in']))
{
$uid = ($this->session->userdata['logged_in']['userId']);
$data['notifyCount']= $this->notifications->getUnreadNotification($uid);
$data['title']= $this->notifications->getUnreadNotificationTitle($uid);
$data['notifyCount']= $this->notifications->getUnreadNotification($uid);
$data['users'] = $this->user->getUserNames();
$msg = $this->vacancyModel->confirmVacancyApplication($uid,$this->input->post());
$msgText = $msg['msg'];
$msgType = $msg['type'];
//Loading View
if($msgType == "danger")
{
$this->session->set_flashdata('msgconfirmed', '<div class="alert alert-danger text-center">'.$msgText.'</div>');
}
else
{
$this->session->set_flashdata('msgconfirmed', '<div class="alert alert-success text-center">'.$msgText.'</div>');
}
redirect(base_url('index.php/studentDashboardController/displayVacanciesApplied'));
}
else
{
$this->load->view('login/loginView');
}
}
3.Model- vacancyModel->confirmVacancyApplication
public function confirmVacancyApplication($uid, $post)
{
$vid = $post['vid'];
$data = array(
'availability' => $vid+""
);
$this->db->where("uid", $uid);
$status = $this->db->update("studentprofile", $data);
if($status)
{
$msg = "You have successfully confirmed";
$type = "success";
$msgData = array(
'msg' => $msg,
'type' => $type
);
return $msgData;
}
else
{
$msg = "Sorry. This vacancy could not be confirmed";
$type = "danger";
$msgData = array(
'msg' => $msg,
'type' => $type
);
return $msgData;
}
}
Interfaces
Any suggestions in this regard will be highly appreciated.
You are closing the before submit button.
Put form after input type="submit" tag. It will work

Load different data in popup on buttotn click for different rows

I have a table which shows multiple rows data taken from database.
There is one button in every row. So what i want, when i click on the button it should be show a popup and data would be shown of that particular row.
for example, when i click on button on the first row, popup with the data of first row will be shown.if i click the button on second row, the data of second row will be shown.
The problem is, when i click on the button of the first row or second row i am getting the same data in the popup of two different row.
so, how can i get the different data in every popup related to different rows?
This my code of view in which i have taken value from controller and shown
CONTROLLER
public function get_job()
{
$data['result'] = $this->user_model->view_job();
if (!empty($data['result']))
{
$this->load->view('admin_view',$data);
}
else
{
$email = $_SESSION['email'];
$data['result'] = $this->user_model->get_username($email);
$this->load->view('no_job',$data);
}
}
MODEL
//To get recently added jobs by inner join
public function view_job()
{
$this->db->select('add_job.*, crm_accounts.company');
$this->db->from('add_job');
$this->db->join('crm_accounts', 'add_job.cid = crm_accounts.id', 'inner');
$this->db->where('add_job.status', 'NEW');
$query = $this->db->get();
return $query->result_array();
}
VIEW
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
<th>Job Id</th>
<th>Job Name</th>
<th>Company Name</th>
<th>Company Id</th>
<th>More</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($result as $object)
{
?>
<td><?php echo $object['id']?></td>
<td><?php echo $object['job_id']?></td>
<td><?php echo $object['job_name']?></td>
<td><?php echo $object['company']?></td>
<td><?php echo $object['cid']?></td>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#MyModal">
Details
</button>
</td>
</tr>
<div id="MyModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="modal-title"><h3>Company Name :<?php echo $object['company']?></h3></div>
</div>
<div class="modal-body">
<h3>Id: <?php echo $object['id']?></h3>
<h3>Job Name: <?php echo $object['job_name']?></h3>
<h3>Job Id: <?php echo $object['job_id']?></h3>
<h3>Paper Size: <?php echo $object['paper_size']?></h3>
<h3>Paper Type: <?php echo $object['paper_type']?></h3>
<h3>Cutting Size: <?php echo $object['cutting_size']?></h3>
<h3>Sheet: <?php echo $object['sheet']?></h3>
<h3>Lamination: <?php echo $object['lamination']?></h3>
<h3>Print Type: <?php echo $object['print_type']?></h3>
<h3>Ctp By: <?php echo $object['ctp_by']?></h3>
</div>
<div class="modal-footer">
<form method="post" action="admin_view">
<button type="button" name="accepted" value="accept" class="btn btn-success">Accept Job</button>
</form>
<button type="button" class="btn btn-danger" data-dismiss="modal">Reject Job</button>
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
</div>
<?php } ?>
</div>
</div>
</div>
</td>
</tbody>
</table>
Reason for same modal is opening each time you click on different row's button is the same ID of each modal. What you need to do is change the data-target of modal to be different for each row. To do this append counter or the ID or the row after the DIV ID of the modal.
Like this,
Your button code will look something like this,
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#MyModal<?php echo $object['id']?>">
Details
</button>
And code of Modal will look something like this,
<div id="MyModal<?php echo $object['id']?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="modal-title">
<h3>Company Name :<?php echo $object['company']?></h3>
</div>
</div>
<div class="modal-body">
<h3>Id: <?php echo $object['id']?></h3>
<h3>Job Name: <?php echo $object['job_name']?></h3>
<h3>Job Id: <?php echo $object['job_id']?></h3>
<h3>Paper Size: <?php echo $object['paper_size']?></h3>
<h3>Paper Type: <?php echo $object['paper_type']?></h3>
<h3>Cutting Size: <?php echo $object['cutting_size']?></h3>
<h3>Sheet: <?php echo $object['sheet']?></h3>
<h3>Lamination: <?php echo $object['lamination']?></h3>
<h3>Print Type: <?php echo $object['print_type']?></h3>
<h3>Ctp By: <?php echo $object['ctp_by']?></h3>
</div>
<div class="modal-footer">
<form method="post" action="admin_view">
<button type="button" name="accepted" value="accept" class="btn btn-success">Accept Job</button>
</form>
<button type="button" class="btn btn-danger" data-dismiss="modal">Reject Job</button>
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
</div>
<?php } ?>
</div>
</div>
</div>
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
<th>Job Id</th>
<th>Job Name</th>
<th>Company Name</th>
<th>Company Id</th>
<th>More</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($result as $object)
{
?>
<td><?php echo $object['id']?></td>
<td><?php echo $object['job_id']?></td>
<td><?php echo $object['job_name']?></td>
<td><?php echo $object['company']?></td>
<td><?php echo $object['cid']?></td>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#MyModal_<?php echo $object['id']?>">
Details
</button>
</td>
</tr>
<div id="MyModal_<?php echo $object['id']?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="modal-title"><h3>Company Name :<?php echo $object['company']?></h3></div>
</div>
<div class="modal-body">
<h3>Id: <?php echo $object['id']?></h3>
<h3>Job Name: <?php echo $object['job_name']?></h3>
<h3>Job Id: <?php echo $object['job_id']?></h3>
<h3>Paper Size: <?php echo $object['paper_size']?></h3>
<h3>Paper Type: <?php echo $object['paper_type']?></h3>
<h3>Cutting Size: <?php echo $object['cutting_size']?></h3>
<h3>Sheet: <?php echo $object['sheet']?></h3>
<h3>Lamination: <?php echo $object['lamination']?></h3>
<h3>Print Type: <?php echo $object['print_type']?></h3>
<h3>Ctp By: <?php echo $object['ctp_by']?></h3>
</div>
<div class="modal-footer">
<form method="post" action="admin_view">
<button type="button" name="accepted" value="accept" class="btn btn-success">Accept Job</button>
</form>
<button type="button" class="btn btn-danger" data-dismiss="modal">Reject Job</button>
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
</div>
<?php } ?>
</div>
</div>
</div>
</td>
</tbody>
</table>
Try this code. i thing. you problem will resolved.

how to load dynamic database on modal window from dynamic table in php

Hello i want to show dynamic data by using MySQL database base on modal window please give me some demo for that. I am trying to show dynamic data on table and as i click on button of any record it must show that dynamic data on modal window as well
this is what i have tried
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("mymodalbody").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("mymodalbody").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "show.php?q=" + str, true);
xmlhttp.send();
}
}
</script>
<script>
function getPage(id) {
$('#output').html('<img src="LoaderIcon.gif" />');
jQuery.ajax({
url: "get_page.php",
data:'id='+id,
type: "POST",
success:function(data){$('#output').html(data);}
});
}
</script>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" >
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 class="modal-title" style="text-align:center;">Information</h3>
</div>
<div class="modal-body" id="mymodalbody">
<?php ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default " data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="container" >
<div class="row">
<div class="col-lg-12 ">
<table class="table table-bordered " style="text-align:center;">
<thead >
<tr style="background-color:#FFF;" >
<th style="text-align:center;">Sr.</th>
<th style="text-align:center;">Name</th>
<th style="text-align:center;">Email</th>
<th style="text-align:center;">Mobile No</th>
<th style="text-align:center;">View</th>
</tr>
</thead>
<tbody>
<?php
$i=1;
$sql=mysql_query("select * from staff order by id asc") or die(mysql_error());
while($row=mysql_fetch_array($sql))
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['mobile'];?></td>
<td><a data-toggle="modal" data-target="#myModal" value="<?php echo $row['id']; ?>" onclick="showHint(this.value)" ><i class="fa fa-eye"></i></a>
</td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<!--end green board -->
</div>
</div>
<ul class="pagination" >
<li>1</li>
<li class="active">2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>`
</div>

Categories