my db has members, and statuses. each member can have 1 current status.
I have a code that decides what status to give what member. thing is, it can give 2 possible statuses, and then the site admin should approve one of them(if at all)

I made a report page with a table, each row has a member-status that is waiting approval/decline.
I added a check box near each row so that the admin can check multiple statuses and approve/deny them at one click (added a add/deny all checked button)
but now I have a problem, what if the admin checks 2 boxes for the same member (when there are more than 1 possible status).. this shouldn't be possible, so then I thought, make a radio button instead, but if I group all radio buttons (as I did with the checkboxes, I pass them as an array when the approve all button is clicked) then I can chose only 1 status no matter how many members are in the table..if I group the radio buttons for each member, how do I pass all the radio buttons that were checked using POST?
I can't think on any other solution..
there's also the problem that I don't really know how many statuses each member has, so I can't group them as I print them. I just use the select *from tbl query and it prints the someone's status 1 by 1 so how can I know who's will be the next status printed? I can only check after it's printed if it's the same as the one before..
hmm...need help ASAP please! sort of last minute mistake I found, too stressed to even think straight!

Recommended Answers

All 3 Replies

Something like this should work, where the name has the format status_"id_user": status_1, status_2 ... status_23.

<input type="radio" name="status_1" value="to be" /> to be
<input type="radio" name="status_1" value="not to be" /> not to be

<input type="radio" name="status_2" value="to be" /> to be
<input type="radio" name="status_2" value="not to be" /> not to be

<input type="radio" name="status_3" value="to be" /> to be
<input type="radio" name="status_3" value="not to be" /> not to be

This will give you:
$_POST
$_POST
$_POST

Then use array_keys to extract user ids, you will end up with something similar to this:

<?php
$a = array_keys($_POST);
$array = array();
foreach($a as $key)
{
	if(preg_match('/status/i',$key))
	{
		$b = explode('_',$key);
		echo 'id: ' . $b[1] . ' value: ' . $_POST[$key];
		
		# uncomment below to build an array
		# $array[] = array($b[1] => $_POST[$key]);
	}
}

#print_r($array);
?>

hope it's useful, bye :)

this is great, thank you so much! but now I see that if I click one of the radio buttons I can't unclick it..so if the report has 40 statuses and 30 were checked and then u click one more by mistake u can't undo it(in a case where the admin doesn't want to approve nor deny a status at that time)..
so I think maybe adding a javascript check if 2 statuses were checked for the same member and show error popout so the admin can uncheck on box and continue..

Yes you can, in dojo I use:

function unsetRadio() {
    dojo.query('#group1 input[type=radio]:checked').attr('checked',false);
}

it should be simpler with getElementById, bye.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.