i created an appointments table where user1 would add appointments and user2 would accept/reject the appointment. now my problem is when the accept and reject are clicked it is displayed in the table respectively but i just cant understand how to add the insert query into it so that it could be inserted into the db. i tried several methods in trying to insert the state[accept/reject] into the db but i found no success. i would request someone to pls provide me some help inn fixing the issue. Thanks.
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>appoinment ID</th>
<th>Date</th>
<th>time</th>
<th>teacher</th>
<th>parent</th>
<th> accept/reject </th>
<th>label</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($conn, "select * from `app` left join `par` on par.par_id=app.par_id
left join `tea` on tea.tea_id=app.tea_id
ORDER BY app_id DESC");
if($query === false)
{
throw new Exception(mysql_error($conn));
}
while($row=mysqli_fetch_array($query))
{
$ann_id=$row['app_id'];
$date=$row['date'];
$msg=$row['time'];
$username = $row['username'];
$username = $row['p_username'];
?>
<tr>
<td><?php echo $row['app_id'] ?></td>
<td> <?php echo date('j/m/y',strtotime($row['date'])); ?></td>
<td><?php echo $row['time'] ?></td>
<td><?php echo $row['p_username'] ?></td>
<td><?php echo $row['username'] ?></td>
<td>
reject
accept
</td>
<td>
<div class="chgtext">PENDING</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>
One way is to pass the ID via query string (GET). So you would update the appointment if the appropriate query string key-pairs are given.
Personally, I believe you should not mix querying while outputting. Do the database stuff at the top first and leave the outputting at the bottom.
Note: I am not too familiar with mysqli_ but it would be something like this:
<?php
// accept or reject appointment with ID
if (isset($_GET['state'], $_GET['app_id'])) {
$stmt = mysqli_prepare($conn, "UPDATE app SET state = ? WHERE app_id = ?");
mysqli_stmt_bind_param($stmt, "sd", $_GET['state'], $_GET['app_id']);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
// query appointments
$query = mysqli_query($conn, "
SELECT * FROM app
LEFT JOIN par ON par.par_id = app.par_id
LEFT JOIN tea on tea.tea_id = app.tea_id
ORDER BY app_id DESC
");
?>
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>appoinment ID</th>
<th>Date</th>
<th>time</th>
<th>teacher</th>
<th>parent</th>
<th>accept/reject</th>
<th>label</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($query)) : ?>
<tr>
<td><?= $row['app_id'] ?></td>
<td><?= date('j/m/y', strtotime($row['date'])) ?></td>
<td><?= $row['time'] ?></td>
<td><?= $row['p_username'] ?></td>
<td><?= $row['username'] ?></td>
<td>
<!-- upon clicking a link, it will redirect to the same page with a query string -->
reject
accept
</td>
<td>
<div class="chgtext">PENDING</div>
</td>
</tr>
<?php endwhile ?>
</tbody>
</table>
</form>
Related
I have this table:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Agent</th>
<th>TWWID</th>
<th>Start Date</th>
<th>Issue</th>
<th>Comment</th>
<th>Overview</th>
<th>Action</th>
<th>TL</th>
<th>Qfinity ID</th>
<th>MSISDN</th>
</tr>
</thead>
<tbody>
<?php
//get records from database
$sql_list = "SELECT * FROM `coaching`";
$sql_list_result = $mysqli->query($sql_list);
if($sql_list_result->num_rows > 0){
while($row = $sql_list_result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row['ID']; ?></td>
<td><?php echo $row['Agent']; ?></td>
<td><?php echo $row['TWWID']; ?></td>
<td><?php echo $row['Start_Date']; ?></td>
<td><?php echo $row['Issue']; ?></td>
<td><?php echo $row['Comment']; ?></td>
<td><?php echo $row['Overview']; ?></td>
<td><?php echo $row['Action']; ?></td>
<td><?php echo $row['TL']; ?></td>
<td><?php echo $row['Qfinity_ID_1']; ?></td>
<td><?php echo $row['MSISDN']; ?></td>
</tr>
<?php } }else{ ?>
<tr><td colspan="5">Nema brojeva u bazi.....</td></tr>
<?php } ?>
</tbody>
</table>
In this table i have sortable heders and first column is defoult sorted ASC, but i want the 3'rd column to be sorted by default DESC.
I include in my .php this js (//cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js)
then I add in .php this script
<script>
$(document).ready(function() {
$('#datatable').DataTable( {
"aaSorting": [[ 3, "desc" ]]
} );
} );
</script>
My table still have sort by 1'st column [ID]
how can i change default sorting?
I faced the same problem and I solved it with the following code. Please try if it can help:
<script>
$(document).ready(function() {
$('#datatable').DataTable( {
"order": [[ 3, "desc" ]]
});
});
</script>
Why does the last 'In Stock' field replaces every other 'In Stock' field when I'm trying to place value on the quantity?
<form action="add_sales.php" method="POST">
<table class="table table-striped table-bordered table-hover results table-fixed">
<thead>
<tr>
<th class="text-center">#</th>
<th>Product Name</th>
<th>Description</th>
<th>Price</th>
<th>In Stock</th>
<th style="width: 20%">Quantity</th>
</tr>
<tr class="warning no-result">
<td colspan="8"><i class="fa fa-warning"></i> No Product Found</td>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM products";
$exec = mysqli_query($connection, $query);
$a = 1;
$b = 1;
while ($row = mysqli_fetch_array($exec)) {
$product_id = $row['product_id'];
$product_name = $row['product_name'];
$product_price = $row['sell_price'];
$description = $row['description'];
$product_quantity = $row['quantity'];
}
?>
<tr>
<td class="text-center"><?php echo $product_id; ?><input type="hidden" name="product_id[]" value="<?php echo $product_id; ?>"></td>
<td><?php echo $product_name; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $product_price; ?></td>
<td><input type="number" name="hehe" value="<?php echo $product_quantity; ?>" id="<?php echo "qtyResult" . $a++; ?>" disabled></td>
<td><input type="number" name="qtyBuy[]" id="<?php echo "qtyBuy" . $b++; ?>" onkeyup="updateStock(this, event)"></td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="form-group">
<input type="submit" name="addCart" value="Add Items to Cart" class="btn btn-info pull-right">
</div>
</form>
Here is my jQuery script. I think the problem is in the var inStock's value. When I change the var inStock's value to a fixed number, it's working fine.
function updateStock(obj, event) {
var inputQty = obj.value;
var inStock = "<?php echo $product_quantity; ?>";
$(obj).closest('tr').find('input[id^="qtyResult"]').val(inStock - inputQty);
}
Because $product_quantity will be set to the last value in the loop.
If you view source and look at the javascript function, you will see it reads:
function updateStock(obj, event) {
var inputQty = obj.value;
var inStock = "234"; //or whatever the last value was
$(obj).closest('tr').find('input[id^="qtyResult"]').val(inStock - inputQty);
}
As the values can change after the page has loaded (and therefor after php has quit) you should grab the current value from the dom when you need it:
function updateStock(obj, event) {
var inputQty = obj.value;
var quantityInput = $(obj).closest('tr').find('input[id^="qtyResult"]');
quantityInput.val(quantityInput.val() - inputQty);
}
I want to refresh my table automatically when i add new row in database. I don't have any idea to create it.
<div class="row">
<div class="col-md-6">
<legend>Typy Darmowe</legend><hr>
<table class="table" id="types-free">
<thread>
<tr>
<th>ID</th>
<th>Mecz</th>
<th>Typ</th>
<th>Data Dodania</th>
<th>URL</th>
</tr>
</thread>
<tbody>
<?php foreach($types as $type) { ?>
<tr>
<td><?php echo $type->t_id; ?></td>
<td><?php echo $type->t_match; ?></td>
<td><?php echo $type->t_type; ?></td>
<td><?php echo $type->t_date; ?></td>
<td><?php echo $type->t_url; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
You need to use AJAX calls. I see you don't have pagination. One easy way to do this is to create an AJAX call that return the count of items from table and then refresh the entire page. Get the count from back end every 1 second. Store the count in a hidden element for comparison. Refreshing the entire page will also update the count stored in hidden field
setTimeout(function(){
var request = $.ajax({
url: "countRows.php",
method: "GET"
});
request.done(function( data ) {
if($('#count').val() != data.count) {
location.reload();
}
});
}, 1000);
Getting the counter:
<?php
// countRows.php
// -- run sql 'SELECT count(id) FROM table_name
// get the count value
echo json_encode(['count' => $count]);
HTML:
<input type="hidden" id="count" value="<?php echo count($types);?>"/>
<div class="row">
<div class="col-md-6">
<legend>Typy Darmowe</legend><hr>
<table class="table" id="types-free">
<thread>
<tr>
<th>ID</th>
<th>Mecz</th>
<th>Typ</th>
<th>Data Dodania</th>
<th>URL</th>
</tr>
</thread>
<tbody>
<?php foreach($types as $type) { ?>
<tr>
<td><?php echo $type->t_id; ?></td>
<td><?php echo $type->t_match; ?></td>
<td><?php echo $type->t_type; ?></td>
<td><?php echo $type->t_date; ?></td>
<td><?php echo $type->t_url; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
If you want advanced and complex table manipulation made only on front end without refresing the entire page you can take a look at datatables
I am trying to display name and age in a single field of the table and I want data to be displayed in the place of . I tried the code below but it doesn't work.
CODE:
<?php
$con=mysqli_connect("localhost","root","","dva");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM apform");
while($row = mysqli_fetch_array($result)) {
echo "My Mood: ";
echo $row['mood'];
echo "<br>";
}
?>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Doctor</th>
<th>Telephone</th>
<th>Mobile</th>
<th>Meeting Time</th>
<th>Fee</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Name"><span> <?php echo $row['name']; ?> </span></td>
<td data-title="Relationship"><span> </span></td>
<td data-title="Address"><span> </span></td>
<td data-title="Telephone"><span> </span></td>
<td data-title="Mobile"><span> </span></td>
<td data-title="Contact at night"><span> </span></td>
<td data-title="Next of kin"><span> </span></td>
<td data-title="Delete"><span> </span></td>
</tr>
You can easily achieve what you need to putting the while loop inside of your table and echoing out all of the relevant fields.
<?php
$con=mysqli_connect("localhost","root","","dva");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM apform");
while($row = mysqli_fetch_array($result)) {
echo "My Mood: ";
echo $row['mood'];
echo "<br>";
}
?>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Doctor</th>
<th>Telephone</th>
<th>Mobile</th>
<th>Meeting Time</th>
<th>Fee</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td data-title="Name"><span><?php echo $row['name']; ?></span></td>
<td data-title="Relationship"><span><?php echo $row['relationship']; ?></span></td>
<td data-title="Address"><span><?php echo $row['address']; ?></span></td>
<td data-title="Telephone"><span><?php echo $row['telephone']; ?></span></td>
<td data-title="Mobile"><span><?php echo $row['mobile']; ?></span></td>
<td data-title="Contact at night"><span><?php echo $row['contact']; ?></span></td>
<td data-title="Next of kin"><span><?php echo $row['nok']; ?></span></td>
<td data-title="Delete"><span>Delete</span></td>
</tr>
<?php } ?>
</tbody>
I have an HTML table. I need to get specific cell value if column is checked! For each row I have a checkBox.
<table id="tabellaOrdinaFarmaci" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Codice Farmaco</th>
<th>Nome Farmaco</th>
<th>Quantità </th>
<th>Quantità di alert</th>
<th>Stato</th>
<th>Quantità da ordinare</th>
<th></th>
</tr>
</thead>
</thead>
<tbody>
<?php
foreach ($query as $row):
$quantitaDaOrdinare = $row->alert - $row->quantita;
if ($quantitaDaOrdinare > 0) {
?>
<tr id="<?php echo $row->aic; ?>" >
<td ><?php echo $row->aic; ?></td>
<td name="nomeFarmac"o><?php echo $row->denominazione ?></td>
<td><?php echo $row->quantita; ?></td>
<td><?php echo $row->alert; ?></td>
<td><?php echo $row->stato; ?></td>
<td>
<input type="text" class="form-control auto" name="codiceFarmaco" value="<?php echo $quantitaDaOrdinare ?>"/>
</td>
<td> <label>
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> ">
</label></td>
</tr>
<?php
} else {
}
endforeach;
?>
</tbody>
I need (using javascript or jquery) to get, if a button is clicked, every value of cell that have name="nomeFarmaco" for every row that is checked! I try to call this function whe
function getValue(){
var nome = $('input[name="checkBox"]:checked').map(function() {
return $(this).parent().parent().parent().find('name="nomeFarmaco').val();
}).get();
return nome;}
but nome is an empty array! any ideas? thanks in advance!
You can put a custom attribute for the check box and set the value in this attribute.
Like this :
<input type="checkbox" name="checkBox" value="<?php echo$row->aic; ?> " customattr="<?php echo $row->denominazione ?>">
And you javascript function will be :
function getValue(){
var nome = $('input[name="checkBox"]:checked').attr('customattr');
return nome;
}
I think this is typo?
<td name="nomeFarmac"o><?php echo $row->denominazione ?></td>
Change it to:
<td name="nomeFarmaco"><?php echo $row->denominazione ?></td>
And you are targetting a <td> and .val() won't work. Should be .text()
var name = [];
$('input[name="checkBox"]').click(function(){
if($(this).is(':checked')) {
name.push($(this).parent().parent().siblings('td[name="nomeFarmaco"]').text());
} else {
var index = name.indexOf(name);
name.splice(index, 1);
}
console.log(name);
});