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 :)
HelgeLindAsked:
Who is Participating?
 
GaryCommented:
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.
0
 
GaryCommented:
<input <?php if (isset($_GET['kat'])) {echo 'checked="checked"';} ?>  name="kat" type="checkbox"   value="<?php echo $row_kategori['kat']; ?>" />
0
 
HelgeLindAuthor Commented:
sorry, do not work with this url

samepage.php?kat=101&kat=100&kat=103&kat=102
0
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.

 
GaryCommented:
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
0
 
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head><body>
<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']; ?>" />
 </label>
 <?php } while ($row_category = mysql_fetch_assoc($category)); ?>
<input name="search" type="submit" id="search" value="search" /> 
</form></div>
Result:
<table> 
Result  here:
</table>

</body>
</html>
<?php
mysql_free_result($schema);
mysql_free_result($kategori);
?>

Open in new window

0
 
HelgeLindAuthor Commented:
Thanks that works
0
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.