php - filtering table by choosing in combobox -


I need to get a list of patient's diagnosis by choosing his name in the combo box, how can I do this ? This is my code.

  & lt; Select name = "pname" class = "textfields" id = "model" style = "width: 180px;" Onchange = "getVal1 ();" & Gt; & Lt; Option id = "0" & ​​gt; - Choose the patient's name - & lt; / Options & gt; & Lt ;? Php $ con = mysqli_connect ("localhost", "root", "", "dbnepecific"); If (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } $ Pnum = $ _GET ['Panam']; $ Query = mysqli_query ($ con, "SELECT * FROM tblnpatient"); While ($ line = mysqli_fetch_array ($ query)) {$ pnum = $ row ['pnum']; $ Pname = $ row ['pname']; $ Addr = $ row ['addr']; $ Complaints = $ line ['complaints']; ? & Gt; & Lt; Option id = "& lt ;? php echo $ pnum ;? & gt;" Data-pnum = "& lt ;? php echo $ pnum ;? & gt;" Data-edit = "& lt ;? php eko $ adr ?? gt;" Data-complaints = "& lt ;? php $ complaints echo;; & gt;" Value = "& lt ;? php echo $ pname;? & Gt;" & Gt; & Lt ;? Php echo $ pname; ? & Gt; & Lt; / Options & gt; & Lt ;? Php}? & Gt;  

This is my code for filtering the table: And I have trouble in this code because the notifications appear in the table when I pname

  & Lt ;; Php $ con = mysqli_connect ("localhost", "root", "", "dbnepecific"); If (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } $ Pname = $ _GET ['pname']; $ Result = mysqli_query ($ con, "SELECT * FROM tbldiagnosis WHERE pname = '$ pname'"); While ($ line = mysqli_fetch_array ($ result)) {echo '& lt; Tr class = "record"> '; Echo '& lt; Td> $ Line ['diagnosis']. '& Lt; / Td> '; }? & Gt;  

This can be easily done using AJAX. On the change of selection, you can trigger a jQuery call to submit the selected value of the box on your PHP page, which contains MySQL to filter the table. After that the given result will be displayed on the page in the specified area.

Home page:

  & lt; Choose Name = "pname" & gt; & Lt; Option value = "pname-value" & gt; Pname-value & lt; / Options & gt; & Lt; / Select & gt; & Lt; Br> & Lt; Div id = "query_results" & gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ('select [name = "pname"]). (' Change ', function () {var curpname = $ (this) .val (); $ .ajax ( {Type: 'GET', url: 'urltotable.php? Pname =' + + curname, success: function (data) {$ ("div # query_results"). Html (data);}})}})}}; & Lt; / script & gt;  

This is a simplified AJAX call that will get value from the selection box called "Pinnam" and "URL" in "AGX" variable "GET "This page can then take that variable through GET and get it to get the query result Upon successful completion, it will display the results inside the div which we had added with the "query_results" id.

You use the below listed options to easily customize your selection

Now for the above "urltotable.php" you can use the table query described above, but just make sure to add it to the GET line so that your PNA Be accessible for variable variables. Kript:

  $ pname = $ _ GET [ "pname"];  

For more information about Ajax for a full list of features,


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -