0

I have multiple themes in my database and my query is to fetch the common info of these themes by selecting check boxes in php? suppose there are four themes 'a', 'b', 'c' and 'd' I have separate tables too containing there common data i.e. a table of a intersect b, a intersect c and a intersect d and so on.

now what i have tried is first user have to select the theme form a drop box , then will select the multiple comparing themes using check box. When i check two themes it displays the data of last theme only.

<form method="GET" action="abc.php" name="form">
   <font size = "4px", color = "#008C9A", align = "left"><b> Select Theme >> </b></font>    
   <select name ="table[]">
     <option value="ab">a</option>
     <option value="bc">b</option>
     <option value="cd">c</option>
   <br/>
   <font size="4px" color="#008C9A" align="centre">
    <b> Show Common Genes of Selected Theme with </b>
   </font> <br/> <br/>
   <input type="checkbox" name="search" value = "a"/> 
    <font color = "#2F4F4F"><b>a </b></font>                         
   <input type="checkbox" name="search" value = "a"/>
    <font color = "#2F4F4F"><b>b</b></font>                       
   <input type="checkbox" name="search"/ value = "c"> 
    <font color = "#2F4F4F"><b>c</b></font>                         
   <input type= "submit" value= "Search" name="sub" /> 
</form>

can any one suggest me what should be my action.php?

i am trying this but it is giving no results:

    <?php
    require("config.php");

    $table=$_POST['table'];
    $search=$_POST['search'];

  echo"<table border='0', width='1200', align='center'>
<tr>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Theme</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Id</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Symbol</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Name</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Synonyms</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>Chromosome</font></th>
<th bgcolor = '#2F4F4F' align = center><font color = '#fff'>New_Id</font></th>

</tr>";

        foreach($search as $key)
        {

switch($key)
            {
      case"cancer":         
   $sql = mysql_query("select * from $table where theme = 'cancer'", $con);
    $num_row=mysql_num_rows($sql);


    for($i=0;$i<$num_row;$i++)
{

$result=mysql_fetch_assoc($sql);


  echo"<tr bgcolor = '#EBDDE2'>";
  echo"<td align=center><font color = 'purple'><b>" . $result['theme'] ."</b></font></td>";

    $strName2 = $result["Locus_id"];
   echo"<td align=center><font color = 'purple'><b>" . $result['id'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['symbol'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['name'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Synonyms'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Chromosome'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['new_id'] ."</b></font></td>";
  echo"</tr>";
}
    break;          

    case"diabetes":         
   $sql = mysql_query("select * from $table where theme = 'diabetes'", $con);
    $num_row=mysql_num_rows($sql);


    for($i=0;$i<$num_row;$i++)
{

$result=mysql_fetch_assoc($sql);

echo"<tr bgcolor = '#EBDDE2'>";
  echo"<td align=center><font color = 'purple'><b>" . $result['theme'] ."</b></font></td>";

    $strName2 = $result["Locus_id"];
   echo"<td align=center><font color = 'purple'><b>" . $result['id'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['symbol'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['name'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Synonyms'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Chromosome'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['new_id'] ."</b></font></td>";
  echo"</tr>";
}
}
    break;          

            case"tubersulosis":         
   $sql = mysql_query("select * from $table where theme = 'tuberculosis'", $con);
    $num_row=mysql_num_rows($sql);


    for($i=0;$i<$num_row;$i++)
{

$result=mysql_fetch_assoc($sql);

echo"<tr bgcolor = '#EBDDE2'>";
  echo"<td align=center><font color = 'purple'><b>" . $result['theme'] ."</b></font></td>";

    $strName2 = $result["Locus_id"];
   echo"<td align=center><font color = 'purple'><b>" . $result['id'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['symbol'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['name'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Synonyms'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Chromosome'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['new_id'] ."</b></font></td>";
  echo"</tr>";
}
}
    break;
            case"hiv":          
   $sql = mysql_query("select * from $table where theme = 'HIV'", $con);
    $num_row=mysql_num_rows($sql);


    for($i=0;$i<$num_row;$i++)
{

$result=mysql_fetch_assoc($sql);

echo"<tr bgcolor = '#EBDDE2'>";
  echo"<td align=center><font color = 'purple'><b>" . $result['theme'] ."</b></font></td>";

    $strName2 = $result["Locus_id"];
   echo"<td align=center><font color = 'purple'><b>" . $result['id'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['symbol'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['name'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Synonyms'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['Chromosome'] ."</b></font></td>";
  echo"<td align=center><font color = 'purple'><b>" . $result['new_id'] ."</b></font></td>";
  echo"</tr>";
}
}
    break;
        }
            }

mysql_close($con);
    ?>
2
  • Use name="search[]" instead of just search Commented Mar 18, 2015 at 10:59
  • value for second checkbox should be b. you are using same value in first two checkboxes. Commented Mar 18, 2015 at 12:39

2 Answers 2

1

As suggested by @manoj change the name to search[] instead of search. And make the form method to POST.

Now in abc.php you can get the checkbox value by

$search = $_POST['search'];//this will be an array

The rest i think you can do. right ?

Sign up to request clarification or add additional context in comments.

Comments

0

Your form code should be:

<form method="POST" action="abc.php" name="form"> <!-- You can keep GET as well -->
   <font size="4px" color="#008C9A" align="left"><!-- no impact but extra , removed-->
    <b> Select Theme >> </b>
   </font>    
   <select name="table"> <!-- why using [] if multiple option can't be selected -->
    <option value="ab">a</option>
    <option value="bc">b</option>
    <option value="cd">c</option>
   </select> <!-- Important: missing close select tag -->
   <br/>
   <font size="4px" color="#008C9A" align="center">
    <b> Show Common Genes of Selected Theme with </b>
   </font> <br/> <br/>
   <input type="checkbox" name="search[]" value="a" /> <!-- name should use [] notation if multiple values -->
    <font color = "#2F4F4F"><b>a </b></font>                         
   <input type="checkbox" name="search[]" value="b" /> <!-- Note value change here -->
    <font color="#2F4F4F"><b>b</b></font>                       
   <input type="checkbox" name="search[]" value="c" /> <!-- extra / removed -->
    <font color="#2F4F4F"><b>c</b></font>                         
   <input type="submit" value="Search" name="sub" /> 
</form>

In your PHP file, you can access values:

$search = $_POST['search']; // checkbox values
print_r($search);

$table = $_POST['table']; // select value
echo $table;

11 Comments

actually my problem is if i check multiple check boxes its gives value of only last one. i have used $search = $_POST['search']; select * from table where theme = ". $search ."'
Your SQL should be "select * from table where theme = '".implode(",", $search) ."'"
thanx apul but it is also not working. In fact it is giving no output.
can you use print_r($search); Also did you replaced your HTML to my provided one? your HTML had some issues.
yup i have corrected my html page according to yours. but where to use print_r($search)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.