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 $ table variable is $ _ POST ['tables'] Specify the value.

Here is the relevant part of my code:

  $ 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);  

Html & gt; & Lt; Top & gt; & Lt; Script & gt; Function sort reset (str) {var e = document.getElementById ("first drop"); var str1 = e.options [e.selectedIndex] .value; Var E = document.getElementById ("Second Dropper"); Var str = e.options [e.selectedIndex] .value; if (str == "") {document.getElementById ("Result"). InnerHTML = ""; Return; } If (window.XMLHttpRequest) {// code for IE7 +, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest (); } Else {// code for IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); } Xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate == 4 & xmlhttp.status == 200} {document.getElementById ("result"). InnerHTML = xmlhttp.responseText;}} xmlhttp.open (" GET "," results.php? Q = "+ str +" & amp; t = "+ str1, true); xmlhttp.send ();} & lt; / script> & lt; / head & gt; & Lt; body & gt; & lt;! - Database name - & gt; & lt; name select name = "tablename" id = "firstdrop" & gt; & lt; option selected = 'selected' value = "Yourdatabasename1"> db1 gt; option value = "yourdatabasename2" & gt; db2 gt; & gt; select / gt; & lt ;! - Sort by - & gt; & lt; Choose Name = "Sortb" ID = "Second Drop" & gt; & lt; Option Selected = 'Selected' value = "slno"> slno & lt; / option> gt; option value = "name" & gt; name & lt; / option & gt; & lt; option value = "author "& Gt; Author & lt; / option & gt; & lt; / select & gt; & lt; button id =" sub "onclick =" sortResult (") & gt; Click & lt; / button & gt; & Lt; br & gt; & lt; Br> & Lt; Div id = "result" & gt; & Lt; B & gt; Results will be listed here. & Lt; / B & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;

results.php

  & 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;   

Modify accordingly.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -