简体   繁体   中英

I want to fetch checkbox values from mysql database

I want to fetch checkbox values from mysql database . I have tried loop and array but it's not working

Here My Php Code

  <form action="" name="color1" id="color1" method="post"> 
  <br />
  <?php
  $count=10;
  $querycolor=mysql_query("select color,id from products order by id");
  while($rowcolor=mysql_fetch_array($querycolor))
  $count++;
  {
  for($i=0; $i<=count; $i++) {    
  $colors=$rowcolor['color'][$i];
  $colorid=$rowcolor['id'];
  }
   ?>
 <input name="checkbox[]" type="checkbox" id="checkbox[]" value="" onclick="window.location='search.php?<?php echo $colors ?>';"><?php echo $rowcolor['color'];?><br /> 
 <?php }?>       
 </form>

For Example I Want To Display Checkbox Values Like This

1) White (2)<br>
2) Black (3)<br>
3) Blue (10)<br>

Use COUNT() function:

Query:

SELECT count(id) as cnt, color, id
FROM products 
GROUP By color
order by id

Then you can print cnt like $rowcolor['cnt'];

You can do it like this

<form action="" name="color1" id="color1" method="post"> 
  <br />
  <?php
  $count=10;
  $querycolor=mysql_query("select color,id from products order by id");
  while($rowcolor=mysql_fetch_array($querycolor))
  $count++;
  {
  for($i=0; $i<=$count; $i++) {    
  $colors=$rowcolor['color'][$i];
  $colorid=$rowcolor['id'];
         ?>
 <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $colors.'('.$colorid.')';?>" onclick="window.location='search.php?<?php echo $colors ?>';"><?php echo $rowcolor['color'];?><br /> 
 <?php } } ?>       
 </form>

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM