im trying to loaded the vehicle details using ajax and data modal dialog. but seem that the data does not loaded correctly and i cant seem to figured out what is wrong with codes.
<div class="container" style="width:900px;">
<h3 align="center">View All Available Vehicle</h3>
<br />
<div class="table-responsive">
<table class="table table-striped">
<tr>
<th width="40%">Plate Number</th>
<th width="20%">Type</th>
<th width="20%">Status</th>
<th width="10%">View</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["plateNo_vehicle"]; ?></td>
<td><?php echo $row["vehicle_Type"];?></td>
<td><?php echo $row["vehicle_status"];?></td>
<td><input type="button" name="view" value="more" id="<?php echo $row["id_vehicle"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
data modal dialog used to display the details.
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Vehicles Details</h4>
</div>
<div class="modal-body" id="vehicle_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
this is the select.php that i used
<?php
if(isset($_POST["vehicle_id"])) {
$output = '';
$link=msqli_connect("localhost","root","root","vms");
$query = "SELECT * FROM vehicle WHERE id_vehicle = '".$_POST["vehicle_id"]."'";
$result = mysqli_query($link, $query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td width="30%"><label>Plate No</label></td>
<td width="70%">'.$row["plateNo_vehicle"].'</td>
</tr>
<tr>
<td width="30%"><label>Engine Number</label></td>
<td width="70%">'.$row["engineNo_vehicle"].'</td>
</tr>
<tr>
<td width="30%"><label>Engine Capacity</label></td>
<td width="70%">'.$row["engineCapacity_vehicle"].'</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
script used
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var vehicle_id = $(this).attr("id_vehicle");
$.ajax({
url:"select.php",
method:"post",
data:{vehicle_id:vehicle_id},
success:function(data){
$('#vehicle_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
Have a look at your select.php file:
<?php
if(isset($_POST["vehicle_id"])) {
$output = '';
$link=msqli_connect("localhost","root","root","vms"); <========
TYPO. It should've been:
$link=mysqli_connect("localhost","root","root","vms");
Also,
Add a data-vehicleid attribute to your view_data button:
<td><input type="button" data-vehicleid="<?php echo $row["id_vehicle"]; ?>" name="view" value="more" id="<?php echo $row["id_vehicle"]; ?>" class="btn btn-info btn-xs view_data " /></td>
And then change your script to receive that attribute value:
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var vehicle_id = $(this).attr("data-vehicleid"); <=====
$.ajax({
....
});
});
});
</script>
Right now, you've set it to :
var vehicle_id = $(this).attr("id_vehicle");
which won't work as you don't have an attribute called id_vehicle="..." on that button. I'm guessing you meant attr("id");
Add this code on your while loop
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["plateNo_vehicle"]; ?></td>
<td><?php echo $row["vehicle_Type"];?></td>
<td><?php echo $row["vehicle_status"];?></td>
<td><input type="button" name="view" value="more" data-vehicle-id="<?php echo $row["id_vehicle"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
And in script change your id var vehicle_id = $(this).attr("data-vehicle-id");
Hope this code work
in order to get the id of this this you need to add onclick
<td><input type="button" name="view" value="more" id="<?php echo $row["id_vehicle"]; ?>" class="btn btn-info btn-xs view_data" onclick="getId(this.id)"/></td>
function getId(clicked_id){
var vehicle_id = clicked_id;
$.ajax({
url:"select.php",
method:"post",
data:{vehicle_id:vehicle_id},
success:function(data){
$('#vehicle_detail').html(data);
$('#dataModal').modal("show");
}
});
}
Here is updated code for view:
view:
<div class="container" style="width:900px;">
<h3 align="center">View All Available Vehicle</h3>
<br />
<div class="table-responsive">
<table class="table table-striped">
<tr>
<th width="40%">Plate Number</th>
<th width="20%">Type</th>
<th width="20%">Status</th>
<th width="10%">View</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["plateNo_vehicle"]; ?></td>
<td><?php echo $row["vehicle_Type"];?></td>
<td><?php echo $row["vehicle_status"];?></td>
<td>more</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
Script:
<script>
$('#dataModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var vehicle_id = button.data('vehicle_id')
var modal = $(this)
$.ajax({
url:"select.php",
method:"POST",
data:{vehicle_id:vehicle_id},
success:function(data){
modal.find('.modal-body').html('No Response');
modal.find('.modal-body').html(data);
$('#vehicle_detail').html(data);
$('#dataModal').modal("show");
}
});
});
</script>
Related
I have a table with data that is being pulled from a database and I am trying to add a button to where it will load more data but when I click on it no data comes up. I am new to coding so I don't have that much experience.
This is the main page
Index.php
<?php
include 'database.php'; // MySQL Connection
$query = "SELECT * FROM Clever_Students";
$result = mysqli_query($conn, $query);
?>
<body>
<br /><br />
<div class="container">
<br />
<div class="table-responsive">
<br />
<h4 align="center">Student Data Management</h4>
<div class="table-responsive">
<table class="table table-striped">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th width="20%" class="text-center">View Student Details</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["First_name"]; ?></td>
<td><?php echo $row["Last_Name"]; ?></td>
<td><input type="button" name="view" value="view" id="<?php echo $row["Student_id"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
<!-- Employee Details -->
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Student Details</h4>
</div>
<div class="modal-body" id="student_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var Student_id = $(this).attr("Student_id");
$.ajax({
url:"select.php",
method:"post",
data:{Student_id:Student_id},
success:function(data){
$('#student_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
</body>
This where the modal should be pulling the data from.
select.php
<?php
if (isset($_POST["Student_id"])) {
$output = '';
include 'database.php'; // MySQL Connection
$query = "SELECT * FROM Clever_Students WHERE Student_id = '" . $_POST["Student_id"] . "'";
$result = mysqli_query($conn, $query);
$output .= '
<div class="table-responsive">
<table class="table table-striped">';
while ($row = mysqli_fetch_array($result)) {
$output .= '
<tr>
<td width="30%"><label>First Name</label></td>
<td width="70%">' . $row["First_name"] . '</td>
</tr>
<tr>
<td width="30%"><label>Last Name</label></td>
<td width="70%">' . $row["Last_Name"] . '</td>
</tr>
<tr>
<td width="30%"><label>Gender</label></td>
<td width="70%">' . $row["Gender"] . '</td>
</tr>
<tr>
<td width="30%"><label>School ID</label></td>
<td width="70%">' . $row["School_id"] . '</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
I have added the code above. Anything will help.
Bootstrap modal did not pop up after 10 record of data table pagination.
i don't know why so please help me.
i had many tried to solve this but i cant understand this.
I don't know idea about jquery so please give me ans.
Here is my php code:
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Sr No</th>
<th>Title</th>
<th>Description</th>
<th>Status</th>
<th>Deadline Date</th>
<th>Add</th>
<th>Show</th>
</tr>
</thead>
<tbody>
<?php
$str = 1;
foreach ($getplan as $key => $get) {
?>
<tr>
<td><?php echo $str; ?></td>
<td><?php echo $get['title']; ?></td>
<td><?php echo $get['description'] ?></td>
<td><?php echo $get['color'] ?></td>
<td><?php echo $get['end_date'];?></td>
<td>
<?php echo $get['members'] ?><br/>
</i>Add Member
</td>
<td>
<input type="button" name="view" value="Show" id="<?php echo $get['id'] ?>" class="btn btn-info btn-xs view_data" />
</td>
</tr>
<?php
$str++;
}
?>
Here is my Modal:
<div id="dataModal" class="modal fade">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Employee Tast Details</h4>
</div>
<div class="modal-body" id="employee_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
Here my script:
<script type="text/javascript">
$(document).ready(function(){
$('.view_data').click(function(){
var employee_id = $(this).attr("id");
$.ajax({
url:"<?php echo base_url('welcome/show'); ?>",
method:"post",
data:{employee_id:employee_id},
success:function(data)
{
$('#employee_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
Please change jQuery code, use click event like this --
$('body').on('click','.view_data',function(){
Instead Of --
$('.view_data').click(function(){
Currently, Your click event not working.
I am trying to update the contents of the table by pressing the update button in PHP using the MySQL connection. I want to combine Ajax and PHP, because by using that I don't have to refresh the page every time.
I don't have any idea to do this. And I haven't found anything on the internet. So I came here to ask.
Here you see a picture of how my current page looks like.
My table
The code I use to generate/populate the table:
<div class="col-md-12">
<h3 class="title">Active Tasks</h3>
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>Task</th>
<th>Predecessor</th>
<th>Dev</th>
<th>MOSCOW</th>
<th>Plan</th>
<th>Do</th>
<th>Check</th>
<th>Act</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, $SQL);
while ($row = mysqli_fetch_array($query)) {?>
<tr class="active">
<td style="display:none;><?php echo $row['ID'];?></td>
<td style="display:none;"><?php echo $row['ProjectID'];?></td>
<td><?php echo $row['Task'];?></td>
<td><?php echo $row['Predecessor'];?></td>
<td><?php echo $row['Dev'];?></td>
<td><?php echo $row['MOSCOW'];?></td>
<td class="js-Task-Plan"><?php echo $row['Plan'];?></td>
<td class="js-Task-Do"><?php echo $row['Do'];?></td>
<td><?php echo $row['Check'];?></td>
<td><?php echo $row['Act'];?></td>
<td>
<button type="button" class="js-TimerStart btn btn btn-default">Start</button>
<button type="button" class="js-TimerPauzeer btn btn-default">Pauzeer</button>
<button type="button" class="js-TimerResume btn btn-default">Resume</button>
<a class="btn btn-default btn-info" href="editTask.php?TaskID=<?php echo $row['ID'];?>&projectid=<?php echo $ID;?>">Aanpassen</a>
<a class="btn btn-default btn-danger" href="delete_task.php?TaskID=<?php echo $row['ID'];?>&projectid=<?php echo $ID;?>">Verwijderen</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<button class="btn btn-block btn-default btn-success" name="UpdateTable"><span style="font-weight: bold;">Update</span></button>
</div>
Thank you for every bit of response and information.
Its not too big issue.
You have to just give some class and ids to your table row and tds.
first of all give unique ids to all rows, in your case you have
<?php echo $row['ID'];? and give same class to all rows these will use later steps.
and give data-id to each row with unique id...so
every tr may be named with <tr id='tr_<?php echo $row['ID'];?>' class='projects' data-id='<?php echo $row['ID'];?>'> and Predecessor td witl be <td id='p_<?php echo $row['ID'];?>'></td>
now i am asssuming that you want to update each project Predecessor every 3 seconds..then just you need to write ajax call for updation.
setInterval(function(){
$('.project').each(function(){
var id=$(this).data('id');
$.ajax({
url:'php_file _name_that_takes_project_id_and_get_details_from_database',
data:{id:id},
type:'POST',
sucess:function(data){
// here data is returned value by ajax php file call which takes project id and fetch Predecessor related to this id.
$('#p_'+id).html(data);
}
});
});
, 3000);
Put it in separate script:
<?php
$query = mysqli_query($conn, $SQL);
while ($row = mysqli_fetch_array($query)) {?>
<tr class="active">
<td style="display:none;><?php echo $row['ID'];?></td>
<td style="display:none;"><?php echo $row['ProjectID'];?></td>
<td><?php echo $row['Task'];?></td>
<td><?php echo $row['Predecessor'];?></td>
<td><?php echo $row['Dev'];?></td>
<td><?php echo $row['MOSCOW'];?></td>
<td class="js-Task-Plan"><?php echo $row['Plan'];?></td>
<td class="js-Task-Do"><?php echo $row['Do'];?></td>
<td><?php echo $row['Check'];?></td>
<td><?php echo $row['Act'];?></td>
<td>
<button type="button" class="js-TimerStart btn btn btn-default">Start</button>
<button type="button" class="js-TimerPauzeer btn btn-default">Pauzeer</button>
<button type="button" class="js-TimerResume btn btn-default">Resume</button>
<a class="btn btn-default btn-info" href="editTask.php?TaskID=<?php echo $row['ID'];?>&projectid=<?php echo $ID;?>">Aanpassen</a>
<a class="btn btn-default btn-danger" href="delete_task.php?TaskID=<?php echo $row['ID'];?>&projectid=<?php echo $ID;?>">Verwijderen</a>
</td>
</tr>
<?php } ?>
and call it 'table.php'.
and add js code, which will be make AJAX call to table.php and update our table
$.ajax('table.php', {
success: function(data) {
$('.table-bordered.table-condensed tbidy').html($(data));
$('#notification-bar').text('The page has been successfully loaded');
},
error: function() {
$('#notification-bar').text('An error occurred');
}
});
I want to show a hidden div when I mouse over a link on my table cell. The event only fires up on the first row. This is what i did:
$(document).ready(function(){
$("#show_div").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseover(function() {
$("#hello").css('visibility', 'visible');
});
$("#hello").mouseout(function() {
$("#hello").css('visibility', 'hidden');
});
});
<form action="" method="post">
<table class="table table-bordered table-hover">
<div id="bulkOptionContainer" class="col-xs-4">
<select class="form-control" name="bulk_options" id="">
<option value="">Select Option</option>
<option value="publish">Publish</option>
<option value="draft">Draft</option>
<option value="delete">Delete</option>
</select>
</div>
<div class="col-xs-4">
<input class="btn btn-success" type="submit" name="submit" value="Apply"/>
<a class="btn btn-primary" href="posts.php?source=add_post">Add New</a>
</div>
<thead>
<tr>
<th><input type="checkbox" name="checkbox[]" id="selectAllCheckBoxes"></th>
<th>Id</th>
<th>Author</th>
<th scope="col">Title</th>
<th>Category</th>
<th>Status</th>
<th>Image</th>
<th>Tags</th>
<th>Comments</th>
<th>Date</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php $query = "SELECT * FROM post ORDER BY post_id DESC";
$result_set = mysqli_query($link, $query);
confirm_query($result_set);
while ($row = mysqli_fetch_assoc($result_set)):?>
<tr>
<td><label><input type="checkbox" class="checkBoxes" name="checkBoxArray[]"
value="<?php echo $row['post_id']; ?>"></label></td>
<td><?php echo $row['post_id'] ?></td>
<td><?php echo $row['post_author'] ?></td>
<td width="100%">
<!-- link to over-->
<a id="show_div"
href="../post.php?p_id=<?php echo $row['post_id'] ?>"><?php echo $row['post_title'] ?></a>
<!-- div to become visible on hover-->
<div id="hello" style="visibility:hidden;">
<p>post</p>
</div>
</td>
<td><?php echo sel_cat_byId($row['post_category_id']) ?></td>
<td><?php echo $row['post_status'] ?></td>
<td><img width="100" class="img-responsive" src="../images/<?php echo $row['post_image'] ?>"></td>
<td><?php echo $row['post_tag'] ?></td>
<td><?php echo $row['post_comment_count']; ?></td>
<td><?php echo $row['post_date'] ?></td>
<td><a class="btn btn-danger" href="posts.php?delete=<?php echo $row['post_id']; ?> "
onclick="alert('Are You Sure?')">Delete</a></td>
</td>
<td><a class="btn btn-success" href="posts.php?source=edit_post&edit=<?php echo $row['post_id']; ?>">Edit</a>
</td>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</form>
****the event only fires up on the first row.
Thanks
First replace your id with class and then try this
$(".show_div").mouseover(function() {
$(this).next(".hello").css('visibility', 'visible');
});
$(".show_div").mouseout(function() {
$(this).next(".hello").css('visibility', 'hidden');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<a class="show_div"
href="#">abc</a>
<!-- div to become visible on hover-->
<div class="hello" style="visibility:hidden;">
<p>post</p>
</div>
I have displayed a table of records using the php while loop.
Also, each row has a corresponding button which is the delete and edit button. I used a certain bootstrap modal for the buttons.
the form is linked to another page
(specifically, success.php?id=)
with the intention of passing the ID of a specific row through its URL. But my problem is that the ID passed will always be the ID of the First row.
so here's the code of my table.
<?php
$sql = mysql_query("SELECT *
FROM foreignlanguage
INNER JOIN sched
ON sched.sched_id = foreignlanguage.schedID
WHERE sched.type='Group' and foreignlanguage.Subject = 'Italian' and
sched.del='1' and (foreignlanguage.area = 'A1' OR foreignlanguage.area = 'A2' OR foreignlanguage.area = 'A3' OR foreignlanguage.area = 'A4' OR foreignlanguage.area = 'A5')");
$count = mysql_num_rows($sql);
if($count != 0)
{
?>
<table class="table table-striped table-hover table-bordered" id="editable-sample">
<thead>
<tr>
<th><div style="width: 45px" >Level</div></th>
<th><div style="width: 60px" >Days</div></th>
<th><div style="width: 70px" >Time</div></th>
<th><div style="width: 90px" >Teacher</div></th>
<th><div style="width: 10px" >Room</div></th>
<th><div style="width: 10px" >Hours</div></th>
<th><div style="width: 15px" >Price</div></th>
<th><div style="width: 10px" >Options</div></th>
</tr>
</thead>
<tbody>
<?php
while( $get_row = mysql_fetch_assoc($sql))
{
$iClass = $get_row['sched_id'];
$iDay = $get_row['day'];
$iTime = $get_row['time'];
$iTeacher = $get_row['teacher'];
$iRoom = $get_row['room'];
$iHour = $get_row['hour'];
$iPrice = $get_row['price'];
$iLevel = $get_row['area'];
$del = $get_row['del'];
?>
<tr class="">
<td><?php echo $iLevel; ?></td>
<td><?php echo $iDay; ?></td>
<td><?php echo $iTime; ?></td>
<td><?php echo $iTeacher; ?></td>
<td><?php echo $iRoom; ?></td>
<td><?php echo $iHour; ?></td>
<td><?php echo $iPrice; ?></td>
<td>
<!-- Delete MODAL-->
<?php
if(isset($_POST['Delete']))
{
header("Location: success.php");
}
?>
<i class="icon-remove icon-white"></i> Delete
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-labelledby="delModal" 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>
<h4 class="modal-title" id="myModalLabel">Delete Schedule</h4>
</div>
<div class="modal-body">
<!--try-->
Are you sure that you want to delete this schedule?
<!--/try-->
</div>
<div class="modal-footer">
<form method='post' action='success.php?id=<?php echo $iClass; ?>' class="form-horizontal">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-danger" name="Delete" value="Delete">
</form>
</div>
</div>
</div>
</div>
<!-- END DELETE MODAL -->
</td>
</tr>
<?php
}
}
else
{
echo "<h4>There are no schedules available yet</h4>";
}
?>
</tbody>
</table>
and here's for the linked page.
<?php include('includes/init.php');
$del_this = $_GET['id'];
$delsched = mysql_query(" UPDATE sched SET del = '0' WHERE sched_id = '$del_this' ") or die(mysql_error("ERROR"));
$delsched_list = mysql_query("UPDATE sched_list SET val = '0' WHERE sched_id = '$del_this' ") or die(mysql_error("ERROR"));
echo $del_this;
header("Location: admin-foreign.php");
?>
pls help me.
There are a number of ways of doing it. You need to have unique ids for your buttons anyway so you may as well have them as Id="EditButton".$rowid and similarly for delete