[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

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 :)
0
HelgeLind
Asked:
HelgeLind
  • 3
  • 3
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now