php i want to add an update button to each row in table that when clicked will automatically change the...












0














So, I have selected a table WHERE status is = 'pending'
and I add edit and delete button to each row
I want to do is when I clicked the edit button it will automatically update
the column status to ='approved'.
So basically I want it to update just by clicking the edit button because column status has only 2 values. Pending and Approved.



This is my code



<?php  
$connect = mysqli_connect("localhost", "root", "", "lms");
$query = "select p.id,
p.empno,fname,lname,loan,amount,amortization,term,dateapplied,dateupdated
FROM application p INNER JOIN accounts a ON p.empno = a.empno WHERE p.status
= 'pending'";
$result = mysqli_query($connect, $query);
?>
<div class="container" style="width:1000px;">

<div class="table-responsive">
<br />
<div id="employee_table">
<table class="table table-bordered">
<tr>
<th>Transaction No</th>
<th>Name</th>
<th>Employee No</th>
<th>Type</th>
<th >Amount</th>
<th >Terms</th>
<th>Amortization</th>
<th>Date</th>
<th colspan = "2" width="7%">Approved</th>
</tr>
<?php
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><?php echo $row["fname"]." ".$row["lname"]; ?></td>
<td><?php echo $row["empno"]; ?></td>
<td><?php echo $row["loan"]; ?></td>
<td><?php echo number_format($row["amount"],2); ?></td>
<td><?php echo $row["term"]; ?></td>
<td><?php echo $row["amortization"]; ?></td>
<td><?php echo $row["dateapplied"]; ?></td>
<td><input type="button" name="update" value="YES" id="<?php echo
$row["id"]; ?>" /></td>
<td><input type="button" name="del" value="NO" id="<?php echo $row["id"];
?>" /></td>
</tr>
<?php
}
?>
</table>


What should I do next? And also I need to update EACH row.










share|improve this question






















  • You want to update the status of html table column on ajax success?
    – Yogendrasinh
    Nov 21 '18 at 14:01












  • uhm anything that can work. Ajax or anything.
    – Jay
    Nov 21 '18 at 14:52
















0














So, I have selected a table WHERE status is = 'pending'
and I add edit and delete button to each row
I want to do is when I clicked the edit button it will automatically update
the column status to ='approved'.
So basically I want it to update just by clicking the edit button because column status has only 2 values. Pending and Approved.



This is my code



<?php  
$connect = mysqli_connect("localhost", "root", "", "lms");
$query = "select p.id,
p.empno,fname,lname,loan,amount,amortization,term,dateapplied,dateupdated
FROM application p INNER JOIN accounts a ON p.empno = a.empno WHERE p.status
= 'pending'";
$result = mysqli_query($connect, $query);
?>
<div class="container" style="width:1000px;">

<div class="table-responsive">
<br />
<div id="employee_table">
<table class="table table-bordered">
<tr>
<th>Transaction No</th>
<th>Name</th>
<th>Employee No</th>
<th>Type</th>
<th >Amount</th>
<th >Terms</th>
<th>Amortization</th>
<th>Date</th>
<th colspan = "2" width="7%">Approved</th>
</tr>
<?php
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><?php echo $row["fname"]." ".$row["lname"]; ?></td>
<td><?php echo $row["empno"]; ?></td>
<td><?php echo $row["loan"]; ?></td>
<td><?php echo number_format($row["amount"],2); ?></td>
<td><?php echo $row["term"]; ?></td>
<td><?php echo $row["amortization"]; ?></td>
<td><?php echo $row["dateapplied"]; ?></td>
<td><input type="button" name="update" value="YES" id="<?php echo
$row["id"]; ?>" /></td>
<td><input type="button" name="del" value="NO" id="<?php echo $row["id"];
?>" /></td>
</tr>
<?php
}
?>
</table>


What should I do next? And also I need to update EACH row.










share|improve this question






















  • You want to update the status of html table column on ajax success?
    – Yogendrasinh
    Nov 21 '18 at 14:01












  • uhm anything that can work. Ajax or anything.
    – Jay
    Nov 21 '18 at 14:52














0












0








0







So, I have selected a table WHERE status is = 'pending'
and I add edit and delete button to each row
I want to do is when I clicked the edit button it will automatically update
the column status to ='approved'.
So basically I want it to update just by clicking the edit button because column status has only 2 values. Pending and Approved.



This is my code



<?php  
$connect = mysqli_connect("localhost", "root", "", "lms");
$query = "select p.id,
p.empno,fname,lname,loan,amount,amortization,term,dateapplied,dateupdated
FROM application p INNER JOIN accounts a ON p.empno = a.empno WHERE p.status
= 'pending'";
$result = mysqli_query($connect, $query);
?>
<div class="container" style="width:1000px;">

<div class="table-responsive">
<br />
<div id="employee_table">
<table class="table table-bordered">
<tr>
<th>Transaction No</th>
<th>Name</th>
<th>Employee No</th>
<th>Type</th>
<th >Amount</th>
<th >Terms</th>
<th>Amortization</th>
<th>Date</th>
<th colspan = "2" width="7%">Approved</th>
</tr>
<?php
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><?php echo $row["fname"]." ".$row["lname"]; ?></td>
<td><?php echo $row["empno"]; ?></td>
<td><?php echo $row["loan"]; ?></td>
<td><?php echo number_format($row["amount"],2); ?></td>
<td><?php echo $row["term"]; ?></td>
<td><?php echo $row["amortization"]; ?></td>
<td><?php echo $row["dateapplied"]; ?></td>
<td><input type="button" name="update" value="YES" id="<?php echo
$row["id"]; ?>" /></td>
<td><input type="button" name="del" value="NO" id="<?php echo $row["id"];
?>" /></td>
</tr>
<?php
}
?>
</table>


What should I do next? And also I need to update EACH row.










share|improve this question













So, I have selected a table WHERE status is = 'pending'
and I add edit and delete button to each row
I want to do is when I clicked the edit button it will automatically update
the column status to ='approved'.
So basically I want it to update just by clicking the edit button because column status has only 2 values. Pending and Approved.



This is my code



<?php  
$connect = mysqli_connect("localhost", "root", "", "lms");
$query = "select p.id,
p.empno,fname,lname,loan,amount,amortization,term,dateapplied,dateupdated
FROM application p INNER JOIN accounts a ON p.empno = a.empno WHERE p.status
= 'pending'";
$result = mysqli_query($connect, $query);
?>
<div class="container" style="width:1000px;">

<div class="table-responsive">
<br />
<div id="employee_table">
<table class="table table-bordered">
<tr>
<th>Transaction No</th>
<th>Name</th>
<th>Employee No</th>
<th>Type</th>
<th >Amount</th>
<th >Terms</th>
<th>Amortization</th>
<th>Date</th>
<th colspan = "2" width="7%">Approved</th>
</tr>
<?php
while($row=mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["id"]; ?></td>
<td><?php echo $row["fname"]." ".$row["lname"]; ?></td>
<td><?php echo $row["empno"]; ?></td>
<td><?php echo $row["loan"]; ?></td>
<td><?php echo number_format($row["amount"],2); ?></td>
<td><?php echo $row["term"]; ?></td>
<td><?php echo $row["amortization"]; ?></td>
<td><?php echo $row["dateapplied"]; ?></td>
<td><input type="button" name="update" value="YES" id="<?php echo
$row["id"]; ?>" /></td>
<td><input type="button" name="del" value="NO" id="<?php echo $row["id"];
?>" /></td>
</tr>
<?php
}
?>
</table>


What should I do next? And also I need to update EACH row.







php ajax crud






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 13:47









Jay

1




1












  • You want to update the status of html table column on ajax success?
    – Yogendrasinh
    Nov 21 '18 at 14:01












  • uhm anything that can work. Ajax or anything.
    – Jay
    Nov 21 '18 at 14:52


















  • You want to update the status of html table column on ajax success?
    – Yogendrasinh
    Nov 21 '18 at 14:01












  • uhm anything that can work. Ajax or anything.
    – Jay
    Nov 21 '18 at 14:52
















You want to update the status of html table column on ajax success?
– Yogendrasinh
Nov 21 '18 at 14:01






You want to update the status of html table column on ajax success?
– Yogendrasinh
Nov 21 '18 at 14:01














uhm anything that can work. Ajax or anything.
– Jay
Nov 21 '18 at 14:52




uhm anything that can work. Ajax or anything.
– Jay
Nov 21 '18 at 14:52












1 Answer
1






active

oldest

votes


















0














You can add class to your buttons:



<input type="button" name="del" class="editbtn" value="NO" id="<?php echo $row["id"]; 


and call ajax by class name and get current button id by this.id:



$(".editbtn").click(function(){
var id = this.id;
$.ajax({url: "test.php?id="+id, success: function(result){
$("#div1").html(result);
}});
});





share|improve this answer





















  • So div1 is? and the test.php?
    – Jay
    Nov 21 '18 at 14:26










  • test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
    – Rahman
    Nov 21 '18 at 15:10












  • so where should i put a query for update?
    – Jay
    Nov 21 '18 at 15:12










  • okay ill try. last question for now that this.id? will i replace the this with the button name?
    – Jay
    Nov 21 '18 at 15:14










  • no , "this" not to be changed. it means current section i'm working on.
    – Rahman
    Nov 21 '18 at 15:23











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413510%2fphp-i-want-to-add-an-update-button-to-each-row-in-table-that-when-clicked-will-a%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can add class to your buttons:



<input type="button" name="del" class="editbtn" value="NO" id="<?php echo $row["id"]; 


and call ajax by class name and get current button id by this.id:



$(".editbtn").click(function(){
var id = this.id;
$.ajax({url: "test.php?id="+id, success: function(result){
$("#div1").html(result);
}});
});





share|improve this answer





















  • So div1 is? and the test.php?
    – Jay
    Nov 21 '18 at 14:26










  • test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
    – Rahman
    Nov 21 '18 at 15:10












  • so where should i put a query for update?
    – Jay
    Nov 21 '18 at 15:12










  • okay ill try. last question for now that this.id? will i replace the this with the button name?
    – Jay
    Nov 21 '18 at 15:14










  • no , "this" not to be changed. it means current section i'm working on.
    – Rahman
    Nov 21 '18 at 15:23
















0














You can add class to your buttons:



<input type="button" name="del" class="editbtn" value="NO" id="<?php echo $row["id"]; 


and call ajax by class name and get current button id by this.id:



$(".editbtn").click(function(){
var id = this.id;
$.ajax({url: "test.php?id="+id, success: function(result){
$("#div1").html(result);
}});
});





share|improve this answer





















  • So div1 is? and the test.php?
    – Jay
    Nov 21 '18 at 14:26










  • test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
    – Rahman
    Nov 21 '18 at 15:10












  • so where should i put a query for update?
    – Jay
    Nov 21 '18 at 15:12










  • okay ill try. last question for now that this.id? will i replace the this with the button name?
    – Jay
    Nov 21 '18 at 15:14










  • no , "this" not to be changed. it means current section i'm working on.
    – Rahman
    Nov 21 '18 at 15:23














0












0








0






You can add class to your buttons:



<input type="button" name="del" class="editbtn" value="NO" id="<?php echo $row["id"]; 


and call ajax by class name and get current button id by this.id:



$(".editbtn").click(function(){
var id = this.id;
$.ajax({url: "test.php?id="+id, success: function(result){
$("#div1").html(result);
}});
});





share|improve this answer












You can add class to your buttons:



<input type="button" name="del" class="editbtn" value="NO" id="<?php echo $row["id"]; 


and call ajax by class name and get current button id by this.id:



$(".editbtn").click(function(){
var id = this.id;
$.ajax({url: "test.php?id="+id, success: function(result){
$("#div1").html(result);
}});
});






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 14:04









Rahman

115




115












  • So div1 is? and the test.php?
    – Jay
    Nov 21 '18 at 14:26










  • test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
    – Rahman
    Nov 21 '18 at 15:10












  • so where should i put a query for update?
    – Jay
    Nov 21 '18 at 15:12










  • okay ill try. last question for now that this.id? will i replace the this with the button name?
    – Jay
    Nov 21 '18 at 15:14










  • no , "this" not to be changed. it means current section i'm working on.
    – Rahman
    Nov 21 '18 at 15:23


















  • So div1 is? and the test.php?
    – Jay
    Nov 21 '18 at 14:26










  • test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
    – Rahman
    Nov 21 '18 at 15:10












  • so where should i put a query for update?
    – Jay
    Nov 21 '18 at 15:12










  • okay ill try. last question for now that this.id? will i replace the this with the button name?
    – Jay
    Nov 21 '18 at 15:14










  • no , "this" not to be changed. it means current section i'm working on.
    – Rahman
    Nov 21 '18 at 15:23
















So div1 is? and the test.php?
– Jay
Nov 21 '18 at 14:26




So div1 is? and the test.php?
– Jay
Nov 21 '18 at 14:26












test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
– Rahman
Nov 21 '18 at 15:10






test.php is file that get your id and update the table and return the result you setted for it. div1 is section you want to be updated for example show the message or show the given result from test.php
– Rahman
Nov 21 '18 at 15:10














so where should i put a query for update?
– Jay
Nov 21 '18 at 15:12




so where should i put a query for update?
– Jay
Nov 21 '18 at 15:12












okay ill try. last question for now that this.id? will i replace the this with the button name?
– Jay
Nov 21 '18 at 15:14




okay ill try. last question for now that this.id? will i replace the this with the button name?
– Jay
Nov 21 '18 at 15:14












no , "this" not to be changed. it means current section i'm working on.
– Rahman
Nov 21 '18 at 15:23




no , "this" not to be changed. it means current section i'm working on.
– Rahman
Nov 21 '18 at 15:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413510%2fphp-i-want-to-add-an-update-button-to-each-row-in-table-that-when-clicked-will-a%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'