Hi,I have 6 checkboxes.
name,father name,city,state,dob,education

What i am trying
1)if user check name,father name its shows only checked item
name father name
Mr. a Mr.abs
Mr. B Mr.bcd
(table structure like that)

2)if user check name,father name,city its shows only checked item
name father name city
Mr. a Mr.abs abc
Mr. B Mr.bcd def
i.e table structure change acc to check box selection.


What i did.
I gave a table structure but fields which are not selected remain empty.
Need suggestion

<?php session_start();
if (!isset($_SESSION['username']))
{
header('Location: login.php');
}
?>

<html>
<head>
<style type="text/css">
table, th
{
border:1px solid #666666;
font-family:Verdana;
font-size:x-small;
vertical-align:top;
}
th
{
background-color:#666666;
color:white;
}
</style>

</head>
<body>
<table width="750px" align="center">
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <tr><td><a href="index.php"><img src="images/home.jpg"></a></td>
  <td align="right"><b>Welcome :&nbsp;</b> <?php echo $_SESSION['username']; ?>&nbsp;&nbsp;<a href="logout.php" >Logout</a></td>
  </tr>
  <tr><td align="center"> <strong>Select:</strong>&nbsp;&nbsp;
  <input type="checkbox" name="a[]" value="name">Name
        <input type="checkbox" name="a[]" value="father">Father Name&nbsp;
 <font color="red">City:</font> <select name="users">
        <?php
        include('db_hindi.php');
        $sql="SELECT DISTINCT city FROM `tbl_hindi`";
        $result =mysql_query($sql);
        while ($data=mysql_fetch_array($result))
        {
        echo "<option value='$data[city]'>$data[city]</option>\n";
        }
        ?>
        </select>
        &nbsp;Gender<select name="gender">
        <?php
        $gen="SELECT DISTINCT gender FROM `tbl_hindi`";
        $result_gen=mysql_query($gen);
        while($row=mysql_fetch_array($result_gen))
        {
        echo "<option value='$row[gender]'>$row[gender]</option>\n";
        }
        ?>

        </select>
        <input type="checkbox" name="a[]" value="address">Address
        <input type="checkbox" name="a[]" value="state">State</td>

        </tr>
        <tr>
        <td align="center">
        <input type="checkbox" name="a[]" value="mobile">Contact
        <input type="checkbox" name="a[]" value="dob">DOB
        <input type="checkbox" name="a[]" value="namdan_date">Namdan date
        </td>

        </tr>
        <tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit"></td></tr>
  </form>
  </table>
  </body>
 </html>
<?php
if(isset($_POST['submit']))
{
$city=$_POST['users'];
$gender=$_POST['gender'];
$sql = "SELECT";
    $check = (array) $_POST['a'];
    for($i = 0; $i < count($check); $i++) 
    {
        $sql .= ($i == (count($check)-1)) ? " `$check[$i]`" : " `$check[$i]`,";
    }
     $sql .= " from tbl_hindi where city='$city' AND gender='$gender' order by gender desc ,namdan_date desc";
    $result = mysql_query($sql);
    $count=count($_POST['a']);
    //echo '<br>'.$count.'<br>';
    //$th="<table border=\"1px black solid\";><tr>";
    //for($j=0; $j<$count; $j++)
        //$th.="<th>$check[$j]</th>";
    //echo $check[$j];
//$result=("SELECT * from tbl_hindi where city='$city'");
//$result = mysql_query("SELECT * from tbl_hindi where city='$city'");
echo "<table border='1' align='center'>
<tr>
<th colspan='8'>Members Details</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['father'] . "</td>";
  echo "<td>" . $row['state'] . "</td>";
  echo "<td>" . $row['city'] . "</td>";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['mobile'] . "</td>";
  echo "<td>" . $row['dob'] . "</td>";
  echo "<td>" . $row['namdan_date'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
}
?>
<div align="center"><a href="javascript:window.print();">Click here to Print</a></div>

What you want to do?You want to format the output?

I only want that table shows acc. to checkbox selection.
Need suggestion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.