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
- <table width="750" cellspacing="10">
- <?php
- $mysql_query = $mysql_connection->prepare('CALL sp_populate_menu_items()');
- $mysql_query->execute();
-
- while($mysql_row = $mysql_query->fetch())
- {
- ?>
- <tr>
- <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>
- <td colspan="2" valign="top" style="font-family: 'Sigmar One', cursive; font-size: x-large;"><?php echo $mysql_row["item_name"]; ?></td>
- </tr>
- <tr>
- <td valign="middle" style="font-family: 'Sigmar One', cursive; font-size: x-large;">BD <?php echo number_format($mysql_row["item_price"], 3); ?></td>
- <td><img src="images/add_to_basket.gif"></td>
- </tr>
- <tr>
- <td colspan="2" valign="top" height="100%" style="border-top: thin double #ff0000;"><?php echo $mysql_row["item_description"]; ?></td>
- </tr>
- <?php } ?>
- </table>