Page 1 of 1

How do I post two Arrays and query one of them?

Posted: Thu May 14, 2015 7:44 am
by simonmlewis
This is in my form:

Code: Select all

	<td valign='top'>
			<input type='checkbox' name='id[]' value='$row->id' id='$row->id'>
        </td>
        
        <td valign='top' align='center'>
			<input type='checkbox' name='star[]' value='yes' id='$row->id'>
        </td>
The idea is if they tick the Star box as well as the ID box, then their comment is awarded a star.
At the top of the page, it does this:

Code: Select all

foreach($_POST['id'] as $id) 
    {
// magic happens
}
So how do I, within the foreach loop, query the star array, and see if there is a YES in the variable??

Re: How do I post two Arrays and query one of them?

Posted: Thu May 14, 2015 8:06 am
by Celauran
Having a value of 'yes', how are you going to know which comment a star belongs to? I'd consider using the comment ID as the star value as well. You could then easily check whether or not a given ID is present in both arrays.

Code: Select all

foreach ($_POST['id'] as $id) {
    if (in_array($id, $_POST['star'], true)) {
        // Comment is checked and starred
    }
}

Re: How do I post two Arrays and query one of them?

Posted: Thu May 14, 2015 8:17 am
by simonmlewis
Great stuff, it works.
Thanks a mill.