Thursday 15 September 2011

php - How to retrieve data from drop down list selection to a table? -


I am trying to learn how to program and this is my first project. I know that I should read the tutorial but I Stuck with it. In fact, want to complete it by itself, but it is getting frustrating. Can someone guide me in the right direction? So, how do I dump data to table cells based on drop down list selection? Any help greatly appreciated the code so far:

  & lt; Select & gt; & Lt; Options & gt; - Choose a lot - & lt; / Options & gt; & Lt ;? Php mysql_connect ('localhost', 'root', ''); Mysql_select_db ('pl_base'); $ Query = "Select LIT_number FROM pl_table"; $ Result = mysql_query ($ query); While (list ($ lot_number) = mysql_fetch_row ($ result)) {resonance "& lt; option value = $" $ Lot_number. " \ "& Gt;" $ Lot_number "& Lt; / option & gt;"; }? & Gt; & Lt; / Select & gt; & Lt; / Br & gt; & Lt; Table range = "1" id = "table" & gt; & Lt; TR & gt; & Lt; Thth width = 80 height = 30> lott & lt; Br / & gt; Number & lt; / Th & gt; & Lt; Width = 110 height = 30> description & lt; / Th & gt; & Lt; Thth width = 90 height = 30> Palette & lt; Br / & gt; Number & lt; / Th & gt; & Lt; Width = 60 height = 30> Net & lt; / Th & gt; & Lt; Width = 60 height = 30> gross & lt; / Th & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; # & Lt; / TD & gt; & Lt; Td rowspan = "5" & gt; Echo results here & lt; / Td> & Lt; TD & gt; & Lt; P & gt; Total & lt; / P & gt; & Lt; / TD & gt; & Lt; TD & gt; # & Lt; / TD & gt; & Lt; TD & gt; # & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TD & gt; # & Lt; / Td> & Lt; Td colspan = "3" & gt; # & Lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Th & gt; & Amp; & Lt; / Th & gt; & Lt; Th & gt; & Amp; & Lt; / Th & gt; & Lt; Th & gt; & Amp; & Lt; / Th & gt; & Lt; Th & gt; & Amp; & Lt; / Th & gt; & Lt; / TR & gt; & Lt; / Table & gt;   

Table in the data base:

  + ---------------------- - --- + ------------------------- + --------- + ------- + | ID | Lot_number | Descr | Pallet_number | Pure | Gross | + -------------------------- + ---------------------- --- + --------- + ------- + | 1 | 111 | Black | 1 | 800 | 900 | 2 | 111 | Black | 2 | 801 | 9 01 | | 3 | 111 | Black | 3 | 802 | 902 | | 4 | 222 | White | 1 | 800 | 900 | 5 | 222 | White | 2 | 801 | 9 01 | | 6 | 222 | White | 3 | 802 | 902 | + -------------------------- + ---------------------- --- + --------- + ------- +    

Choosing a number in a selected element will not directly use PHP because PHP is a server side language, you have to submit the data as a form and then display it.

  & lt ;? Php mysql_connect ('localhost', 'root', ''); Mysql_select_db ('pl_base'); $ Query = "Select LIT_number FROM pl_table"; $ Result = mysql_query ($ query); ? & Gt; & Lt; Form action = "" method = "post" & gt; & Lt; Select name = "option_chosen" & gt; & Lt; Options & gt; - Choose a lot - & lt; / Options & gt; & Lt ;? Php while (list ($ lot_number) = mysql_fetch_row ($ result)) {echo "option" = "" $ lot_number " "\" & Gt; "$ Lot_number." & Lt; / Options & gt; ";}? & Gt; & gt; Selection & gt; & lt; input type =" submit "value =" submit "/> gt; & gt; & gt; & lt; / br & gt; ; & Lt; Table border = "1" id = "table"> gt; & lt; tr & gt; width = 80 height = 30> lot 
number description & lt; / th> & lt; th width = 90 height = 30> palette & lt; br / & gt; numbers & lt; / Th & gt; Width = 60 height = 30> Net & lt; / th> & lt; width = 60 height = 30> gross & lt; / th> & lt; / tr & Gt; & lt ;? Php if ($ _ SERVER ['REQUEST_METHOD'] == 'POST') {$ option_chosen = $ _ POST ['option_chosen']; $ Query = "SELECT * to pl_tabl E WHERE lot_number = '$ option_chosen' "; $ run = mysqli_query ($ query); $ line = mysqli_fetch_array ($ run, MYSQLI_ASSOC); echo" & lt; Tr & gt; & Lt; Td> ". $ Line ['lot_number']." & Lt; / Td> ";" line ['descr']. "And " row $ ['pallet_number'] resonates. "& Lt; / td & gt;"; & Quot; & Quot; TD & gt; & Quot; $ Line ['net'] "& Lt; / td> & lt; td & gt; $ ['Gross'] "& Lt; / td> & lt; / tr & gt;"; }? & Gt; & Lt; / Table & gt;

No comments:

Post a Comment