Hi guys,
Trying to figure out how to pass an ID as a variable from a checkbox.
Basically i have a list of results from mysql displayed, in that table are checkboxes. Now i'm wanting to assign the name of the checkbox as a variable.
No problem there, can be done, what i'm stuck on is how to determine what the ID is when grabbing the POST data.
I have my form like so....
I need a way to check which checkboxes are checked then perform my DB query.
So when i move along to my query i can do....
However i can't do it that way, it simply doesn't work as the variable is a variable obviously.
I'm proberly approaching this in the wrong way, so looking for a fresh head to help me figure it out...
I'll explain more, basically i have news posts stored in a DB table, along with those i have a comments table, the comments have AID set to match the article(news posts) they were posted to.
Now i'm working on the admin section, so i grab a list of news articles, along with those i grab the comments associated.
The checkboxes allow an admin to check if they wish to remove some comments attached to a given article.
So you have a list of comments with checkboxes, so you check which ones you want to remove, then hit Submit and it moves onto the query.
So what i need to do is figure out how to know which boxes were checked.
Any help appreciated.....
I'll post back if i figure it out in any case...
Here's an image to clarify..
Trying to figure out how to pass an ID as a variable from a checkbox.
Basically i have a list of results from mysql displayed, in that table are checkboxes. Now i'm wanting to assign the name of the checkbox as a variable.
No problem there, can be done, what i'm stuck on is how to determine what the ID is when grabbing the POST data.
I have my form like so....
PHP:
<form method="post" action="'.$_SERVER['PHP_SELF'].'">
// Some of my table data
<input type="checkbox" name="'.$myvariable.'">
// Some more table data
<input type="submit" name="submit" value="OK" class="btn" />
So when i move along to my query i can do....
PHP:
if ($_POST['submit'] == ok) {
if(isset($_POST['$myvariable'])) {
$newvar = $_POST['$myvariable'];
}
}
I'm proberly approaching this in the wrong way, so looking for a fresh head to help me figure it out...

I'll explain more, basically i have news posts stored in a DB table, along with those i have a comments table, the comments have AID set to match the article(news posts) they were posted to.
Now i'm working on the admin section, so i grab a list of news articles, along with those i grab the comments associated.
The checkboxes allow an admin to check if they wish to remove some comments attached to a given article.
So you have a list of comments with checkboxes, so you check which ones you want to remove, then hit Submit and it moves onto the query.
So what i need to do is figure out how to know which boxes were checked.
Any help appreciated.....
I'll post back if i figure it out in any case...

Here's an image to clarify..

Last edited: