html - select all option for dropdown using php -
this question has answer here:
- how create select option dropdown? 2 answers
i totally fed of coding part add select option, have added select all, problem how fetch data, mysql database using, select option.
i have 8 tables in ma database , search box have select table query search term show information query term selected table.
here code above:
<form method="post" action="test3.php" name="search_form"> <input type="text" name="search" size=15 maxlength=15 placeholder = "gene symbol"/> <select name="table[]" id = "table[]" size = "0" multiple> <option selected="selected"></option> <option value="infla_info">inflammation</option> <option value="diet_info">diet</option> <option value="obesity_info">obesity</option> <option value="stress_info">stress</option> <option value="athero_info">atherosclerosis</option> <option value="retino_info">diabetic retinopathy</option> <option value="nephro_info">diabetic nephropathy</option> <option value="neuro_info">diabetic neuropathy</option> </select> <input type="submit" name="submit" value="gene search"/>
here value = table name, each table working, multiple tables working, when time select totally fail. have added select option too,, not working in fetching.
can suggest how can select search term in tables of mysql database? beneficial select option think. , secondly should there in value = "" select option.
case "infla_info": //echo "<h1> inflammation </h1>"; $sql = mysqli_query($con, "select * infla_info gene_symbol = '$search'"); $num_row=$sql->num_rows; if ($num_row == 0) { echo "<font color = 'red'>gene not found in inflammation.</font>"; } else { for($i=0;$i<$num_row;$i++) { $result=mysqli_fetch_assoc($sql); echo " <table border='0', width='1000', align='center'> <tr> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>theme</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>locus_id</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>gene_symbol</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>gene_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'>gene summary</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>homologene_id</font></th> </tr> "; echo "<tr bgcolor = '#d3d3d3'>"; echo "<td align=center>"; echo 'inflammation'; echo "</td>"; $strname2 = $result["locus_id"]; $strlink2 = "<a href = 'infla_gene_go.php?gene_id=" . $result['locus_id'] . "'>" . $strname2 . "</a>"; echo "<td align=center><font color = 'black'>" . $strlink2 . "</font></td>"; $strname1 = $result["gene_symbol"]; $strlink1 = "<a href = 'infla_gene_symbol.php?gene_symbol=" . $result['gene_symbol'] . "'>" . $strname1 . "</a>"; echo "<td align=center><font color = 'black'>" . $strlink1 . "</font></td>"; echo "<td align=center><font color = 'black'>" . $result['gene_name'] . "</font></td>"; echo "<td align=center><font color = 'black'>" . $result['synonymns'] . "</font></td>"; echo "<td align=center><font color = 'black'>" . $result['chromosome_no'] . "</td>"; echo "<td height='50px'><div style='height:200px; overflow:scroll;'><font color = 'black'>" . $result['gene_summary'] . "</font></div></td>"; $strname = $result["homologene_id"]; $strlink = "<a href = 'infla_homologene.php?homologene_id=" . $result['homologene_id'] . "'>" . $strname . "</a>"; echo "<td align=center>" . $strlink . "</td>"; echo "</tr>"; } } break; case "stress_info": $sql = mysqli_query($con, "select * stress_info gene_symbol = '$search'"); $num_row=$sql->num_rows; if ($num_row == 0) { echo "<font color = 'red'>gene not found in stress.</font>"; } else { for($i=0;$i<$num_row;$i++) { $result=mysqli_fetch_assoc($sql); echo "<table border='0', width='1000', align='center'> <tr> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>theme</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>locus_id</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>gene_symbol</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>gene_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'>gene summary</font></th> <th bgcolor = '#2f4f4f' align = center><font color = '#fff'>homologene_id</font></th> </tr>"; echo "<tr bgcolor = '#d3d3d3'>"; echo "<td align=center>"; echo 'stress'; echo "</td>"; $strname2 = $result["locus_id"]; $strlink2 = "<a href = 'stress_gene_go.php?gene_id=" . $result['locus_id'] . "'>" . $strname2 . "</a>"; echo "<td align=center>" . $strlink2 . "</td>"; $strname1 = $result["gene_symbol"]; $strlink1 = "<a href = 'stress_gene_symbol.php?gene_symbol=" . $result['gene_symbol'] . "'>" . $strname1 . "</a>"; echo "<td align=center>" . $strlink1 . "</td>"; echo "<td align=center>" . $result['gene_name'] . "</td>"; echo "<td align=center>" . $result['synonymns'] . "</td>"; echo "<td align=center>" . $result['chromosome_no'] . "</td>"; echo "<td height='50px'><div style='height:200px; overflow:scroll;'>" . $result['gene_summary'] . "</div></td>"; //$strname = $result['firstname'] . " " . $result['lastname'] $strname = $result["homologene_id"]; // create link person.php id-value in url // $strlink = "<a href = 'person.php?id = " . $result['id'] . "'>" . $strnavn . "</a>"; $strlink = "<a href = 'stress_homologene.php?homologene_id=" . $result['homologene_id'] . "'>" . $strname . "</a>"; echo "<td align=center>" . $strlink . "</td>"; // echo "<td align=center>" . $result['pmid'] . "</td>"; echo "</tr>"; break; //this counts number or results - , if there wasn't gives them little message explaining } }
above code fetching data tables. please me friends, ma boss going kill me..... thanx in advance.
there may more 1 way it. question not clear me, correct me if i'm wrong. if want select columns more 1 table may try using union
operator. add 'all' option in select box.
<option value='all'>all</option>
first check option value , if it's equal 'all' use union
operator club results different sql queries.
for example have 2 tables:
table1
----------------------- id | name | age | ----------------------- 1 | boo | 12 | ----------------------- 2 | boom | 13 | -----------------------
table2
----------------------- id | name | age | ----------------------- 1 | rofl | 14 | ----------------------- 2 | lol | 15 | -----------------------
now select * table1 union select * table2
result in this:
----------------------- id | name | age | ----------------------- 1 | boo | 12 | ----------------------- 2 | boom | 13 | ----------------------- 1 | rofl | 14 | ----------------------- 2 | lol | 15 | -----------------------
basically need check option value , if it's equal club of results sql queries using union
operator.
for more information visit http://www.w3schools.com/sql/sql_union.asp
Comments
Post a Comment