Re: HELP TO VALIDATE CHECKBOXES
| From: | Bogdan Stancescu | Date: | Fri, 21 Dec 2001 14:39:59 +0000 |
| Subject: | Re: HELP TO VALIDATE CHECKBOXES | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-78470@lists.php.net to get a copy of this message | ||
while ($row = mysql_fetch_array($result))
{
echo $row["name"];
list($checked)=mysql_fetch_row(mysql_query("select user_id from User_Category where
user_id='$current_user' and
category_id='".$row["category_id"]."'"));
$checked=$checked?" checked":"";
echo '<input type="checkbox" name="cat[]"
value='.$row["category_id"].'$checked>';
}
Hope this helps. You'll probably have to change a few letters here and there, but it should
work in the end.
If the costs of connecting to the MySQL server are big then you could grab the categories for the
current user prior to the loop, store them into an array and then echo "checked" if
in_array().
Bogdan
> // (this is referenced as LOOP1 below)
> while ($row = mysql_fetch_array($result))
> {
> echo $row["name"];
>
> echo '<input type="checkbox" name="cat[]"
> value='.$row["category_id"].'$checked>';
> }
>
> HOW do i modify LOOP1 so that i loop the second query $qry to validate which value of
> category_id in each checkbox corresponds to the values returned by my query $qry, and i check ONLY
> THOSE checkboxes, and leave the other checkboxes as unchecked?
>