html - How do I retrieve a td value in PHP based on the row of the submit button pressed? -


i being able see td value based on row 'submit' button in. enter image description here

here html code

<?php foreach($books $booklist) : ?>         <tr>              <form action = "." method = "post">             <input type="hidden" name="action" value="addtocart" >             <td><img height="50" width="50" src=<?php echo "/../../product_manager/uploads/".$booklist['productimage']; ?>></td>                     <td><?php echo $booklist['name']; ?></td>             <td><?php echo $booklist['version']; ?></td>             <td><?php echo $booklist['releasedate']; ?></td>             <td><?php echo $booklist['price']; ?></td>             <td><?php echo $booklist['quantity']; ?></td>              <td><input name="submit" type="submit" value = 'add cart'/><td>             </form>          </tr>         <?php endforeach; ?> 

and here controller

 if($action == 'addtocart'){  echo $booklist['name']; } 

my problem is echoing last row only. if echo version, price etc, echos product named test. how can echo based on submit button row? i'd keep strictly php or html only.

you can give submit button array based name such name="submit[0]". way can use counter variable in loop assign value submit button , determine button pressed.

the above recommendation should use single form element. according html standards, form should not contained in tr element, in td element. therefore form element should contain table , not other way around.

instead of loop, can try reading value as:

$arr = array_keys($_post['submit']); echo $arr[0]; 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -