I am unfamiliar with AJAX and am having a difficult time trying to learn it for what I need.
I need to write ajax calls within a foreach loop.
if i just use PHP calls they will all fire even if i don't use the onclick event.
What im basically doing is writing out a list from the DB and adding a remove button to the row.
when the remove link is clicked, it will fire a query to update a field in the DB for item.
My index.php file
<?php echo $item['item_name']; ?>My PHP code: (note: I am using wordpress's $wpdb to query the WP database. query is valid. There is no user input, and its on an admin page so dont worry about prepare() or other injection defenses. )
$wpdb->query("UPDATE " . $wpdb->prefix."item
SET is_removed =" . $remove_option . "
WHERE item_id =" . $item_id );
?>
($remove_option is populated earlier in the index.php page, and $item_id comes from $items array)
I need to pass 2 variables through the ajax call, populate $remove_option and $item_id.
fire the query, return to index.php page.
How do I use ajax to achieve this? I'm completely unfamiliar with ajax, and i am not using a plugin for WP, only php scripts.