Hello. I have a cycle for the withdrawal of applications:

for($i = 0; $i < $num_result; $i++){ $orders_catalog = pg_fetch_array($ord_result); $order_id = $orders_catalog['order_id']; $ord_name = $orders_catalog['feature_name']; $user_name = $orders_catalog['user_name']; $user_email = $orders_catalog['e_mail']; $user_phone = $orders_catalog['phone']; $subcategory_id = $orders_catalog['sub_name']; $datetime = $orders_catalog['datetime']; $message = $orders_catalog['message']; ?> <div class = "forsinglereq"> <div id = "servname"><span id = "inservname">НАИМЕНОВАНИЕ УСЛУГИ:</span><?php echo $ord_name;?></div><br> <span class = "prefix">Имя:</span> <div class = "inform"><?php echo $user_name;?></div><br> <span class = "prefix">Email:</span> <div class = "inform"><?php echo $user_email;?></div><br> <span class = "prefix">Телефон:</span> <div class = "inform"><?php echo $user_phone;?></div><br> <span class = "prefix">Подкатегория услуги:</span> <div class = "inform"><?php echo $subcategory_id;?></div><br> <span class = "prefix">Дата и время заявки:</span> <div class = "inform"><?php echo $datetime;?></div><br> <span id = "message">Сообщение:</span> <div id = "comment"><?php echo $message;?></div><br> <form action = "./rej_acc_funcs.php" method = "post"> <div id = "accept"><label id = "acceptoo" for = "on">Принять</label></div> <div id = "reject"><label id = "rejectoo" for = "out">Отклонить</label></div> <input id = "on" type = "submit" name = "acceptreq"> <input id = "out" type = "submit" name = "rejectreq"> <input type = "hidden" name = "orderid" value = "<?php echo $order_id;?>"> </form> </div> 

How to take from the loop exactly the array I need in order to reject or accept the application? While from the table the first record is selected. In the handler I transfer id. But I do not know how to pass a specific id. When it is possible to pass on the links using the GET method, there are no problems. But here I get the entire array from the sql table with the query. Help me please.

  • I correctly understand that with the help of the above markup, a list of applications is displayed, one div class = "forsinglereq" - one application? And the problem is how to determine for which application the submit has worked? - Ponio pm
  • That's right, Ponio. - reckless

1 answer 1

Use data attributes. php & HTML:

 <?php $order_id = $orders_catalog['order_id']; ?> <input id = "on" type = "submit" data-order="<?= $order_id?>" name = "acceptreq"> <input id = "out" type = "submit" data-order="<?= $order_id?>" name = "rejectreq"> 

javascript:

 var elem = document.getElementById("on"); console.log(elem.dataset.order); 

In jQuery, you can use the data() method. More about data attributes : The dataset property and data attributes .

  • I do not understand jQuery. But, thanks for the help. - lihim
  • Or do you need pure php? Here is the way to use hidden elements: stackoverflow.com/questions/32286184/… Or use the getAttribute php getAttribute . - Ponio
  • I don't mind learning js. Just constantly something I do not finish and js does not work for me. Initially, I pass the request id to the request handler via input hidden. In the handler, I accept $ id = $ _POST ['name of hidden']. Only all the same, the first record from the database table is selected: - (( - upscale
  • Is the name of the hidden element the same for all applications? Then, of course, only the first will be selected. Try each submit attribute attribute with the request number, then read its value using getAttribute . - Ponio 2:53 pm
  • I delve into the documentation, but I don’t understand how to specifically attribute the attribute with the number of the request for submit and then read it - (( - likhaim