I created a food menu with a webpage checkbox and radio box. I use PHP to get results from a MySQL database table. An example of the code below shows how things are currently set:
PHP includes connecting to the database:
An example of one of PHP is:
$ host = "localhost"; // hostname $ username = "root"; // Enter mysql username here code $ password = "admin2"; // MySQL Password Enter code here $ db_name = "food"; // Database Name Enter the code here $ tbl_name = "fruit"; // table name mysql_connect ("$ host", "$ username", "$ password") or die ("can not connect"); Mysql_select_db ("$ db_name") or die ("can not choose DB"); $ Sql = "SELECT * FROM $ tbl_name"; $ Result_fruits = mysql_query ($ SQL);
Input box on the main page that returns table data (in each category it has its own MySQL table):
& lt ;? Php while ($ line = mysql_fetch_array ($ result_fruits)) {? & Gt; & Lt; Input type = "radio" name = "fruit []" id = "& lt;? $ Rows ['item name'];? & Gt; value =" & lt;? Echo $ rows ['label'] ;? & Gt; "class =" green-border-fruit "/> & lt ;? php while ($ rows = mysql_fetch_array ($ result_cheese)) {? & Gt; input type =" radio "name =" Pie [] "id =" & lt;? $ Rows ['item name'] ;? & Gt; Value = "& lt;? $ Rows echo ['labels'] ;? & gt;" Class = "green-border-paneer" /> & Lt ;? Php while ($ rows = mysql_fetch_array ($ result_desert)) {? & Gt; & Lt; Input type = "radio" name = "desert []" id = "& lt;? $ Rows ['item name'];? & Gt; value =" & lt;? Echo $ rows ['label'] ;? For example, the code above will return:
Apple $ 2 & lt; br & gt; Orange $ 1 & lt; br & gt; Grapes $ 2 & lt; td & gt; Swiss $ 3 & lt; / br & gt; & lt; / td & gt; Blue Paneer $ 1.50 & lt; br & gt; Feta $ 2.20 Cake $ 5
$ 4 Pieces $ 3.50
In a checkbox I All checked items are required.
EX: This will be the amount displayed if (apple, orange, blue)
TOTAL - $ 8.50
Any help will be greatly appreciated.
I use jQuery to select the radio And then I use all the values and put the result with .html in the textfield.
Check the radio button:
and you can loop with all the radio buttons:
$ ('. ClassName '). Combined example: var sum = 0; $ ('radio button') (each (function () {// work here}
. ($ (This (': checked')) {sum = sum + $ (this) .val ();} $ ("# idTextfield"). Html ("Total: "+ Sum +" $ ");
No comments:
Post a Comment