php - Drop down list to select a table and an additional drop down list to filter -
I want to use 2 drop down lists on the same page, selecting one of them from the DB and the table from the other I want to filter the selected table, I think this is very basic but I am new to PHP and SQL. I have no problem submitting the table for the table to be filtered, but I do not know that the Here is the relevant part of my code: results.php Modify accordingly. $ table variable is
$ _ POST ['tables'] Specify the value.
$ table = table_name; If (isset ($ _ POST ['tables'])) {$ table = $ _ POST ['Table']; } // must be filtering by group (true === isset ($ _ POST ['value'])) {if ($ _ POST ['value'] == 'all') {// to get all records query $ query = "SELECT * FROM $ TABLE"; } Other {// filter group $ value = $ _ POST ['value']; $ query = "SELECT * FROM $ table WHERE group = '$ value'"; }} And {// the page is loaded for the first time $ query = "SELECT * FROM $ table ORDER Group Group ASC"; } $ Sql = mysqli_query ($ con, $ query);
& lt ;? Php $ q = $ _GET ['q']; $ t = $ _GET ['t']; $ con = mysqli_connect ('localhost', 'yourusername', 'password', 'database'); If (! $ Con) {dead ('could not connect:' mysqli_error ($ con)); } Mysqli_select_db ($ con, "database"); $ sql = "SELECT * FROM" $ t "Order buy". $ Q; $ Result = mysqli_query ($ con, $ sql); Akho "& lt; Table Boundary = '1' '& gt; & lt; tr & gt; & lt; th & gt; Names & lt; / th & gt; & lt; th & gt; Author & lt; / th & gt; & lt; th & gt; id & lt; / th> & lt; / tr & gt; "; While ($ line = mysqli_fetch_array ($ result)) {resonant "<<" Echo "& lt; td & gt;" . $ Line ['name'] "& Lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['author']. "& Lt; / td>"; Echo "& lt; td & gt;" . $ Line ['slno'] "& Lt; / td & gt;"; Echo "& lt; / tr & gt;"; } Resonates "& lt; / table & gt;"; Echo $ t; Mysqli_close ($ thief); ? & Gt;
Comments
Post a Comment