Checkbox "checked=\"checked\"" from url array

a search page
The form sends to itself
What I want is that, the checkboxes must be checked as the choice before submit in the result

like this:

<form action="samepage.php" method="get">
<?php do {....
<input <?php if (!(strcmp($_GET['kat'],$row_kategori['kat']))) {echo "checked=\"checked\"";} ?>  name="kat[]" type="checkbox"   value="<?php echo $row_kategori['kat']; ?>" />
<?php } while.....

Anyone have a suggestion :)
Who is Participating?
Still not sure I'm following what you are trying to achieve but try...

<input <?php if (in_array($row_kategori['kat'],$_GET['kat'])){echo 'checked="checked"';}?>  name="kat[]" type="checkbox"   value="<?php echo $row_kategori['kat']; ?>" />

If the value of $row_kategori['kat'] exists in the posted array of kat then the checkbox will be checked.
<input <?php if (isset($_GET['kat'])) {echo 'checked="checked"';} ?>  name="kat" type="checkbox"   value="<?php echo $row_kategori['kat']; ?>" />
HelgeLindAuthor Commented:
sorry, do not work with this url

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

A bit confused - you just want to check that all checkboxes are checked before submitting or just one checkbox or...?
Or are you asking how to set the checkbox to checked if previously checked on form submit
HelgeLindAuthor Commented:
I want to show the result of input in the form on submit, while they searched categories will be check t  in the form check boxes. So the user can see what it was I searched for while she sees the results

Here are most of the code

<?php virtual('/connection/file.php'); 
$k2= $_GET['cat'];
if (isset($_GET['from'])) {$from = $_GET['from'];} else {$from = date('Y-m-d');};
if (isset($_GET['to'])) {$to = $_GET['to];} else {$to = date('Y-m-d', strtotime("+2 months"));};
if (isset($_GET['cat']))  {$cat2 = implode(", " ,$k2 );}  else {$cat2 = ' 100,103 ';};

mysql_select_db($database_filer, $filer);
$query_schema = "SELECT pv_akt.akt_id, bla bla bla  FROM bla bla bla WHERE pv_day between '".$from."' and '".$to."' and pv_akt.status   IN(".str_replace("'","",$kat2).") ORDER BY pv_handelser.dag ASC, pv_handelser.tid ASC";
$schema = mysql_query($query_schema, $filer) or die(mysql_error());

mysql_select_db($database_filer, $filer);
$query_category = "SELECT * FROM pv_aktstat ORDER BY sort ASC";
$kategori = mysql_query($query_kategori, $filer) or die(mysql_error());
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<div class="noprint">
<form action="/samepage.php" method="get">
From   <input name="from" type="text" id="from" value="<?php echo $from; ?>" size="10" maxlength="10" />
To <input name="to" type="text" id="to" value="<?php echo $to; ?>" size="10" maxlength="10" />
 <?php do { ?><label><?php echo $row_kategori['status']; ?>
   <input name="cat[]" type="checkbox"   value="<?php echo $row_category['cat']; ?>" />
 <?php } while ($row_category = mysql_fetch_assoc($category)); ?>
<input name="search" type="submit" id="search" value="search" /> 
Result  here:


Open in new window

HelgeLindAuthor Commented:
Thanks that works
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.