0

i'm creating a front end to view a mysql database with options to filter by certain criteria (such as age and sex) as well as options for deleting specific entries in the database.

i used this http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php as a guide to build everything.

so far this is what i have: view.php - authenticates user, creates basic html with input boxes in order to define the filters, a submit button, javascript function that reads the values from the input boxes and calls ajax.php, basic html to display results of mysql query.

ajax.php - connects to the mysql DB, gets the input values from view.php, builds the mysql query from the input values, creates a table of all the mysql query result which is displayed by view.php.

within each row of the mysql query result, i have an html input button which, onclick, calls a javascript function intended for deleting the specific row. so each row has it's own delete button. this delete function right now resides in view.php.

my intention, is that the delete js function will call another file, say delete.php and that delete.php will activate the mysql query to delete the specific row based upon which delete button was clicked.

the only part i don't have working correctly is how to pass the correct row ID to delete.php.

any thoughts?

4

1 回答 1

1

In the onclick event of each button which is generated through php, store the row ID as the parameter of the function which sends that parameter to your delete.php.

Example:

In the php which generates each of your delete buttons:

echo '<input type="button" value="Delete" onclick="delete('. $row_ID .')" />';

Then just make the corresponding AJAX function delete(row_id) in your javascript which will pass that parameter as part of the request to your delete.php.

于 2012-05-04T22:53:25.297 回答