0

This is php mysql code:

<?php $user_apply_data=mysql_query("SELECT * FROM apply");
 while ($user_apply_field = mysql_fetch_assoc($user_apply_data)) {  ?>
<tr>
<td><button class="btn btn-xs btn-success" id="apply" data-send="<?php echo $user_job_field['job_category']; ?>">Apply</button>
</td>
</tr>
 <?php } ?>

This is script:

$("#apply").click(function() {
            var check = $(this).data("send");
    alert(check);
            });

Output : first-row calling function rest are not

4
  • 2
    Please stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy. Commented Dec 7, 2017 at 13:36
  • ID's Must Be Unique, specifically because it will cause problems in JavaScript and CSS when you try to interact with those elements. Commented Dec 7, 2017 at 13:36
  • id="apply" must be unique for all rows. You have identical IDs. Commented Dec 7, 2017 at 13:36
  • i make "apply" as a class and all work fine, Thank you for guiding. <button class="btn btn-xs btn-success apply" data-send="<?php echo $user_job_field['job_category']; ?>">Apply</button> : and : $(".apply").click(function() { Commented Dec 7, 2017 at 20:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.