riscphree
09-13-2007, 12:12 AM
I'm running into a logic problem here. What I'm doing is generating a list of items to be approved, and then have a checkbox in the form when submitted will approve the item and move it to another database table.
My form looks something like this:
Item ID | Item Desc | Item Num | checkbox
for my checkbox, I'm using this:
<input type="checkbox" value="y" name="{$row['item_id'}">
When I submit the form, how can I go through all the submitted results and verify that they were checked? I know how to grab values with php submitted forms, but I've only done simple text input.
bimbiero
09-13-2007, 12:26 AM
Are you just wanting to make sure that they were all checked? When your actually displaying this on the page, are you looping a query? Assume that is what your doing and only wanting to check if they are checked, then you could just grab the database results again and loop through them.
// SQL Code Here
while ($row = mysql ....)
{
if ($_POST($row['item_id'])!="y")
{
// Code for a failure Here
}
}
Now if you were going to try to figure out what was actually selected, you could try a few ways. I would possibly try an array and add it to the array. So then you could have an array containing the id's of the actually check items.
// SQL Code Here
$itemCount=0;
while ($row = mysql ....)
{
if ($_POST($row['item_id'])=="y")
{
$itemArr[$itemCount++] = $row['item_id'];
}
}
Then just make sure that you remember your count starts with zero, so if you loop on it to add one.
(I didn't actually test this code, but its the general idea)
riscphree
09-13-2007, 12:40 AM
Are you just wanting to make sure that they were all checked?
I want to find out which ones are checked, because I want to move those into the new database.
When your actually displaying this on the page, are you looping a query?
Yeah, its a while loop to display it on the page.
Xenatino
09-13-2007, 12:07 PM
foreach ($_POST['delete'] as $Key => $Value)
{
//Delete code
}
<input type=\"checkbox\" class=\"checkbox\" name=\"delete[]\" id=\"delete_" . $Mod['uid'] . "\" value=\"" . $Mod['uid'] . "\" />
That's the way i use for my multiple deletions from a list... might shed some light on it for you.