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

  • Home
  • SEARCH
  • 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 290903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:02:25+00:00 2026-05-12T06:02:25+00:00

I have a html table which if filled by values of an mysql table.

  • 0

I have a html table which if filled by values of an mysql table. This way:

function getCategories(){
    $prod = new C_Product();
    $cat= $prod->getCategorieenAsArray();

    $tr = "";
    foreach ($cat as $key => $value){
        $tr.="<tr><td>&nbsp;</td><td>$value</td><td><img src=\"images/delete_button.gif\"></td></tr>\n";

    }
    return $tr; 

}

Now I want to be able when i press the delete button to remove that row from the database and to refresh the table so that it’s actually removed also from the table on the html page. I want to use for this jQuery and Ajax. That shouldn’t be to difficult for me. My question is how to select the row that is going to be deleted? How would the jquery know which img is pressed?

Should i add a class to the img / tr with a value in it? If I use an id I would have to redefine my jquery function for each row that’s being added and thus doesn’t seem a right solution.

So can anyone please help me further?

Thanks

//edit:

In the mean time I went on my own way to try figure stuff out and I have now a complete ajax call with the correct id.

jQuery(document).ready(function(){

    jQuery("img.deleterow").click(function(){
        id = jQuery(this).parent().attr("id");
        jQuery.ajax({
            type: "POST",
            data: "id=" +id,
            url: "ajax_handler.php",
            success: function(msg){
                jQuery(this).parent().remove();
            }
        });

    });
});

Now the only problem I have is to remove the tr from the table when the id is deleted in the database.
This is how my tr looks like:

$tr.="<tr><td>&nbsp;</td><td>$value</td><td id=\"$key\"><img class=\"deleterow\" src=\"images/delete_button.gif\"></td></tr>\n";
  • 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-12T06:02:25+00:00Added an answer on May 12, 2026 at 6:02 am

    I would defintely add a class to the the img or tr and would also add an ID that has the ID of the element in the database

    but if you don’t it would be somethng like this

    $('img').click(function(){
       var id = $(this ~ tr).attr("id");
       $.ajax(type: "POST",
              url: "some.php",
              data: "id="+id,
              success: function(msg){
                 $(id).remove();
       });
    });
    

    EDIT TO YOUR EDIT:

    Have you tried the $(“#id ~ tr”) selector to remove it? e.g. $(#id ~ tr).remove();

    I would also put the ID on the tr if you are adding IDs then it would be $('#id').remove(); to get rid of the tr

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

Sidebar

Related Questions

I have an html table which i bind data dynamically on the server side
I have a repeater control outputting some HTML. I want a table which outputs
I have an HTML table that looks like this: ------------------------------------------------- |Column 1 |Column 2
This one is weird, I have a page that consists of a html table
I have this file 'gardens.php' , which pulls data from a table called 'generalinfo'
I have a Html Table which consists of rows that were generated dynamically (from
I have a div who needs to filled with an html table through an
I have an html table in which I am placing images side by side
I have a simple html table which has several rows. the following is implemented
I have an HTML table in which the first column's cells each contain a

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.