PHP and jQuery control panel
I'm not sure if this would be the correct place for asking this, but I figured someone on this forum must at least have an idea.
On the control panel of my website I want to create a table with PHP for non-approved user-submitted terms, so that I can approve them depending on if they're not spam or something of the same sort. Only the approved terms will then be shown on the site. To add some nice effects i'm using jQuery. On click of the approved button, I also use its Ajax functions to parse the information to another PHP document which will then execute the SQL query.
Thing is is that only the first approve link works and then when it fades away and is gone, none of the others work anymore. This caused by the lack of unique ID's in the anchor tags. But I have no idea how to give it a unique idea with a variable.. and use that same variable within Ajax..
Here is what I have:
- ...
- $query = "SELECT weed_name, your_name, location FROM Weednames WHERE approved = 'no'";
- $result = mysqli_query($cxn,$query) or die ("Couldn't connect to server. " .mysqli_error($cxn));
-
- echo "<table>\n";
- echo "<tr>\n
- <td>Weed Nickname</td>\n
- <td>Name of Submitter</td>\n
- <td>Location</td>\n
- <td>Approve?</td>\n
- </tr>\n";
- while($row = mysqli_fetch_assoc($result))
- {
- extract($row);
- echo "<tr id='$weed_name'>\n
- <td>$weed_name</td>\n
- <td>by: $your_name</td>\n
- <td>from: $location</td>\n
- <td><a href='#' id='approve' name='$weed_name'>Approve</a></td>\n";
- }
- echo "</table>\n";
- ?>
- <script type="text/javascript">
- $('#').click(function() {
- alert('Handler for .click() called.');
- });
- $(document).ready(function(){
-
- $('#approve').click(function() {
- var weed_name = $('#approve').attr('name');
- alert("Weed name: " + weed_name);
-
- $.ajax({
- type: "POST",
- url: "approve.php",
- data: "weed_name="+ weed_name,
- success: function(){
- $("tr#" + weed_name).fadeOut();
- }
-
- });
-
- return false;
- });
- });
- </script>
Any suggestions?
Thanks in advance!