Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6072225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:08:11+00:00 2026-05-23T10:08:11+00:00

I am new when it comes to PHP, Javascript and AJAX, so sorry if

  • 0

I am new when it comes to PHP, Javascript and AJAX, so sorry if this is a simple question. I am working on plugin; in this plugin I am developing a table in PHP. Users are able to add links to a specific widget to display on their home page. I am trying to make a function with Javascript and AJAX that deletes a row from their list and database. I am trying to assign each TR a unique ID but I am unsure how to do this.. here is my code:

<table id="links" width="350px" border="1">
    <tr>
        <td></td>
        <td><b>Display</b></td>
        <td><b>Link *</b></td>
        <?php       

        if ( isset($_POST['links']) ) {

            $displays = $_POST['displays'];
            $links = $_POST['links'];
            $domain = $_POST['domain'];

            foreach($links as $i => $link) {
                if ( empty($displays[$i]) )
                    $displays[$i] = "";
                if( empty($links[$i]))
                    unset($links[$i]);

            }


            $autodomain = array('displays' => $displays, 'links' => $links, 'domain' => $domain);

            $options = get_option("autodomain_links") or array();
            $options[] = $autodomain;
            //$dump = array();
            update_option("autodomain_links",  $options);

        }
        $options = get_option("autodomain_links");

        if ($options) {

            foreach($options as $option) if ($tmp++ < 15) {

                $displays = $option['displays'];
                $links = $option['links'];
                $domain = $option['domain'];
                foreach($links as $i => $link) 
                {
                    echo '<tr>';
                    echo '<td><a href="#" class="delete"/><img alt="" border="0" src="https://jarkin.its-express-tst.syr.edu/wp-content/uploads/2011/06/delete.png" /></a></td>';
                    echo '<td>' . $displays[$i] . '</td>';
                    echo '<td>' . $link . ' ' . $domain . '</td>';
                    echo '</tr>';
                ;

                }

            }

        }


        ?>

</table>

Here is the Javascript/AJAX:

<script type="text/javascript" >
$(document).ready(function()
        {
            $('table#links td a.delete'').click(function()
            {
                if (confirm("Are you sure you want to delete this row?"))
                {
                    var id = $(this).parent().parent().attr('id');
                    var data = 'id=' + id ;
                    var parent = $(this).parent().parent();

                    $.ajax(
                    {
                           type: "POST",
                           url: "delete_row.php",
                           data: data,
                           cache: false,

                           success: function()
                           {
                                parent.fadeOut('slow', function() {$(this).remove();});
                           }
                     });                
                }
            });
        });
</script>

The Javascript/ajax is using the Table id and the TR id as the parent to identify the row – but since I am using PHP I don’t know how to generate unique IDs for each of the TR’s.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:08:11+00:00Added an answer on May 23, 2026 at 10:08 am

    You can define it by $i:

           foreach($links as $i => $link) 
            {
                echo '<tr id="id_'.$i.'">'; //<--here
                echo '<td><a href="#" class="delete"/><img alt="" border="0" src="https://jarkin.its-express-tst.syr.edu/wp-content/uploads/2011/06/delete.png" /></a></td>';
                echo '<td>' . $displays[$i] . '</td>';
                echo '<td>' . $link . ' ' . $domain . '</td>';
                echo '</tr>';
            ;
    
            }
    

    Then each row’s id is id_{rowNumber}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question comes from my experience with the following question: https://stackoverflow.com/questions/492748/new-responses-icon-on-so-crashes-ie7-closed In that question,
This bit of code comes with new classes that are subclasses of UITableViewController... -
Ok this is more of general technology/approach question. We have a very simple web
I have a simple example of PHP sessions and AJAX, which works when holding
I have a simple comet chat. JavaScript send ajax request with long polling. When
I'm new to PHP, AJAX, and databases. But I want to know what experiences
I am extremely new to PHP and, although I am quite familiar to javascript,
I come from a PHP based background and my new years resolution was to
I need to scroll up the div as the new text comes in. My
How do you stay up-to-date when it comes to new software versions? Above all,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.