Cainiao's question: small questions about PHP and MySQL

Source: Internet
Author: User
Cainiao's question: small questions about PHP and MySQL
What I want to achieve is
Order multiple dishes
Then select a box
Then click Submit Order
The unit price of the selected option is automatically added
Then assign the result to the cost of the selected box, that is, jiesuan
The PHP code is as follows:
 _ ModelExample1 = & FLEA: getSingleton ('Model _ Renwu_caidanguanli '); $ this-> _ modelExample2 = & FLEA: getSingleton ('Model _ Renwu_baoxiangguanli ');} function actiondiancai () {$ this-> authCheck ('9-3'); $ this-> _ edit ($ row);} function _ edit ($ arr) {$ title = 'food click';/* perform database operations * // * database query statement */$ SQL = "select * from renwu_caidanguanli where shoumaizhuangtai = 'sell '"; $ class_info1 = $ this-> _ modelExample1-> findBySql ($ SQL); $ temp = $ this-> _ ModelExample1-> execute ($ SQL);/* Display Data */$ smarty = & $ this-> _ getView (); /* the role of the added post is unknown */$ smarty-> assign ('class _ info1 ', $ class_info1 ); /* display the webpage template * // $ smarty-> display ("Renwu/caidanguanli. tpl "); $ title = 'box click '; /* perform database operations * // * database query statement */$ SQL = "select * from renwu_baoxiangguanli where baoxiangzhuangtai = 'idle '"; $ class_info2 = $ this-> _ modelExample2-> findBySql ($ SQL); $ temp = $ this-> _ modelExample2-> execute ($ SQL );/* Show the data */$ smarty = & $ this-> _ getView ();/* the added field is unknown */$ smarty-> assign ('class _ info2 ', $ class_info2);/* display the webpage template */$ smarty-> display ("Renwu/diancai. tpl ");} function actionChange () {// select $ B = 0 based on the selected menu; $ SQL = "select caipindanjia from renwu_caidanguanli where id = '{_ _ POST ['isover1']}'"; // dump ($ SQL ); // $ this-> _ modelExample-> execute ($ SQL); $ temp = $ this-> _ modelExample1-> findBySql ($ SQL ); // dump ($ temp); exit; $ a = $ temp [0] ['Caipindanjia ']; $ B = $ B + $ a; dump ($ B); exit; // price list of temporary dishes // $ SQL = "update renwu_baoxiangguanli set jiesuan = '$ a' where id =' {$ _ POST ['isover1']} '"; // $ temp = $ this-> _ modelExample1-> execute ($ SQL ); $ SQL = "update renwu_baoxiangguanli set baoxiangzhuangtai = 'in use 'Where id =' {$ _ POST ['isover2']} '"; // $ this-> _ modelExample-> execute ($ SQL); $ temp = $ this-> _ modelExample2-> execute ($ SQL ); // $ SQL = "delete from renwu_caidanguanli where Id = '{$ _ POST ['isdel']} '"; // $ this-> _ modelExample-> execute ($ SQL ); // $ temp = $ this-> _ modelExample-> execute ($ SQL); if ($ temp) {js_alert (null, "window. parent. showMsg ('saved successfully! ') ", $ This-> _ url ('diance');} // else die ('failed to save! ') ;}}?>

The tpl code is as follows:
 

The structure of the dish database is as follows:

The box database structure is as follows:


Reply to discussion (solution)

Click here
Select multiple dishes
Query time
$ SQL = "select caipindanjia from renwu_caidanguanli where id in (". join (',', $ _ POST ['isover1']). ")";

The box seems to be a single button.
The check button also works, but the bottom is valid. Prone to disputes

Click here
Select multiple dishes
Query time
$ SQL = "select caipindanjia from renwu_caidanguanli where id in (". join (',', $ _ POST ['isover1']). ")";

The box seems to be a single button.
The check button also works, but the bottom is valid. Prone to disputes


The box has been changed to single choice
You're right.
I did not consider

I tried your code
The result is the unit price of a random option.
Not sum

Click here
Select multiple dishes
Query time
$ SQL = "select caipindanjia from renwu_caidanguanli where id in (". join (',', $ _ POST ['isover1']). ")";

The box seems to be a single button.
The check button also works, but the bottom is valid. Prone to disputes



Thank you very much.
Solved
I checked it with dump.
I found my own problems
A for loop is made.
Then we implement
Thank you very much for the moderator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.