-3

I have a table:

enter image description here

I want to change "pending" to "payed" when i will click on button "Do" In the database if value of column "status" is 0 , then write pending, and if value is 1 - payed.

Code of table:

$host="localhost"; 
$user="***";
$pass="***"; //установленный вами пароль
$db_name="u0304752_sam";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);

$result=mysql_query("SELECT id,payeer,summa,dates_add, status FROM pays_tnmleafeuj  ORDER BY id DESC"); 

//$result - ассоциированный массив, т.е. таблички, у которой есть названия столбцов 

echo "<table border=1 width=700px>";
echo "<tr><th>ID</th><th>Кошелёк</th><th>Сумма</th><th>Дата</th><th>Статус</th><th>-</th></tr>";
while ($row=mysql_fetch_array($result )){
$id=$row[0];
$payeer=$row[1];
$summa=$row[2];
$data=$row[3];
$status=$row[status];
if($status == 0){
$status = 'pending';
} elseif($status == 1){
$status = 'payed';
} 

echo "<tr><td class=id>$id</td><td>$payeer</td><td>$summa</td><td>".date('Y-m-d H:i', $row[dates_add])."</td><td>$status</td><td><input type=button value=Do SQL></td></tr>";
}
echo "</table>";
General Grievance
  • 4,555
  • 31
  • 31
  • 45

2 Answers2

0

Question is a bit vague but...

Create a listener for your "Do" buttons. Perhaps assign id's to the buttons that match the ID of the database record. Have a section of php that makes an sql update call on the proper table. When the button is clicked, update that records status.

It would be more help if you were to have a more specific question.

0

Checkout this answer

Clicking a button is client side whereas updating database is Server side. So use an ajax call as described in above answer to call some php function which will then update the database.

neV_
  • 53
  • 6
  • please send code... – user name 2 Dec 29 '17 at 18:23
  • @НиколайШейгиц the code is given in the link. Set a listener to your button. In that listener make the ajax call to some php file as post request if you want to send in parameters. And in PHP, update the record in database. – neV_ Dec 29 '17 at 18:27
  • Can you write the code for me..? I try the code... but it not work for my – user name 2 Dec 29 '17 at 19:07