How to use Dynamic Button

How to use Dynamic Button

Hi,

I am using below code to populate from database into my website. I want to know how can I now make a click for btnAddToBasket to pass the item_id in order to add the item to the basket? shall I add it in the data-id of the image? and if yes then how I pass that to the $('#btnAddToBasket').click? but if no then what's the best practice for this scenario?


Thanks,
Jassim


  1. <table width="750" cellspacing="10">
  2. <?php
  3.     $mysql_query = $mysql_connection->prepare('CALL sp_populate_menu_items()');
  4.     $mysql_query->execute();

  5.     while($mysql_row = $mysql_query->fetch())
  6.     {
  7. ?>
  8. <tr>
  9.     <td valign="top" rowspan="3" style="padding-bottom: 20px;"><img id="btnAddToBasket" name="btnAddToBasket" src="images/menu/<?php echo $mysql_row["item_guid"]; ?>.jpg" width="150" height="150" style="border: 1px solid; border-radius: 25px;"></td>
  10.     <td colspan="2" valign="top" style="font-family: 'Sigmar One', cursive; font-size: x-large;"><?php echo $mysql_row["item_name"]; ?></td>
  11. </tr>
  12. <tr>
  13.     <td valign="middle" style="font-family: 'Sigmar One', cursive; font-size: x-large;">BD <?php echo number_format($mysql_row["item_price"], 3); ?></td>
  14.     <td><img src="images/add_to_basket.gif"></td>
  15. </tr>
  16. <tr>
  17. <td colspan="2" valign="top" height="100%" style="border-top: thin double #ff0000;"><?php echo $mysql_row["item_description"]; ?></td>
  18. </tr>
  19. <?php } ?>
  20. </table>