菜鳥提問:關於PHP與MySQL的小問題

來源:互聯網
上載者:User

本人想實現的功能就是
點多個菜品
之後選擇單個包廂
之後點擊提交訂單
所選的選項的單價自動加和
然後把結果賦值給選擇包廂的費用,也就是jiesuan
PHP代碼如下
_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='菜品點選';/* 執行資料庫操作 *//* 資料庫查詢語句 */$sql="select * from renwu_caidanguanli where shoumaizhuangtai='出售'";$class_info1=$this->_modelExample1->findBySql($sql);$temp= $this->_modelExample1->execute($sql);/* 顯示資料 */ $smarty = & $this->_getView();/* 後加的一句 作用不詳 */$smarty->assign('class_info1',$class_info1);/* 顯示該網頁模板 *///$smarty->display("Renwu/caidanguanli.tpl");$title='包廂點選';/* 執行資料庫操作 *//* 資料庫查詢語句 */$sql="select * from renwu_baoxiangguanli where baoxiangzhuangtai='空閑中'";$class_info2=$this->_modelExample2->findBySql($sql);$temp= $this->_modelExample2->execute($sql);/* 顯示資料 */ $smarty = & $this->_getView();/* 後加的一句 作用不詳 */$smarty->assign('class_info2',$class_info2);/* 顯示該網頁模板 */$smarty->display("Renwu/diancai.tpl");}function actionChange(){//根據選擇菜品$b=0;$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;//臨時菜品價格表//$sql="update renwu_baoxiangguanli set jiesuan='$a' where id='{$_POST['isOver1']}'";//$temp= $this->_modelExample1->execute($sql);$sql="update renwu_baoxiangguanli set baoxiangzhuangtai='使用中' 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('儲存成功!')",$this->_url('diancai'));    }//else die('儲存失敗!');  }}?>

tpl代碼如下


菜品資料庫結構如

包廂資料庫結構如


回複討論(解決方案)

點此菜品
菜品應能多選
查詢時
$sql="select caipindanjia from renwu_caidanguanli where id in (" . join(',', $_POST['isOver1']) . ")";

包廂 似應為單選鈕。
複選鈕也行,但是最下面的有效。容易產生糾紛

點此菜品
菜品應能多選
查詢時
$sql="select caipindanjia from renwu_caidanguanli where id in (" . join(',', $_POST['isOver1']) . ")";

包廂 似應為單選鈕。
複選鈕也行,但是最下面的有效。容易產生糾紛


包廂已經改成單選
你說的很對
我之前沒有考慮到

我嘗試了您的代碼
結果是隨機的一個選項的單價
不是和

點此菜品
菜品應能多選
查詢時
$sql="select caipindanjia from renwu_caidanguanli where id in (" . join(',', $_POST['isOver1']) . ")";

包廂 似應為單選鈕。
複選鈕也行,但是最下面的有效。容易產生糾紛



非常感謝
問題解決了
我用dump看了一下
發現是我自己的問題
做了一個for迴圈
然後就實現了
非常感謝版主大大
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.