views:

56

answers:

1

hi all.. i have a datatable which connected to DB... i want make the data inside datatable can be edit and delete... but of course,,after make change at datatable the data inside DB also change..

what's code to do that...??i've been try like this:

$("#datalist tbody").click(function(event) {
                                $(oTable.fnSettings().aoData).each(function(){
                                                $(this.ntr).removeClass("row_selected");
                                                });
                                $(event.target.parentNode).addClass("row_selected");
                                });

i'm newbie at datatable..that code is what i've been reach..and i dont know how to delete data..

1. i can edit/delete data after click at <tbody>
2. show option to edit/delete data
3. if choose delete show (are you sure to delete this data?)
4. the script connected to DB (so we can control DB data)
5. data at DB updated
A: 

Ok, I'm assuming you're using PHP and MySQL... You have to send a SQL query into your database with mysql_query(). Typically an easy way to do this is to go into phpMyAdmin, run the query you want on some debug data, then copy the generated php code:

  1. Step 1

  2. alt text

also, please ignore the disparity in the id field... the idea should still be clear.

The highlighted text in step 2 should be your SQL query to send through PHP. Usually edits/selections/etc. will be shown above the table view in the Browse tab for the SQL query reference.

The next step is to (in best practice) define a $sql variable that contains your query. In this case, I'd put the highlighted text from step 2 into this variable:

$sql = "DELETE FROM faq_1278475018 WHERE id = 9 LIMIT 1";

Then with PHP, run the query: $result = mysql_query($sql);

That deletes things. Keep fiddling with phpMyAdmin and pay attention to the SQL query box to get clues on what SQL queries to run.

The easiest place I've found to follow is w3schools: PHP and MySQL Introduction

That should get you started...

To answer the comment:

You'll want to pass commands to your PHP script using $.post().The syntax is explained here: jQuery $.post()

You also might want to make sure the user is "logged in" in some fashion and that you've taken considerable security measures to ensure that someone doesn't manually post data to your script other than when you want them to.

virstulte
i'm just not already know about jquery or datatable script..for php i'm not confuse.
klox
ok, I posted some info up there about jQuery.post(), a very useful jQuery-assisted way to make ajax calls and send post parameters to a php script without forcing the user to leave the page. Check it out!
virstulte