doumengjing1500 2019-01-29 06:29
浏览 12
已采纳

使用php从其他表数据中划分一个表数据

I had tried to display the divided value of saleprice from the table (additem) and from the table (addbill) data .i.e.quantity that we entered in the addbill table and display the value in the price column in addbill table.

Previously I was done to fetch from one table data from other table data

if(isset($_POST['submit1'])){
  $m = $_POST['itemname'];
  $sp = "SELECT saleprice FROM additem WHERE itemname='$m'";
  $q = mysqli_query($link,$sp);
  $n = mysqli_fetch_assoc($q);
  $saleprice = $n['saleprice'];
  $sql = "INSERT INTO addbill (bill_id,itemname,quantity,price) VALUES 
 ('".$_POST['billid']."','".$_POST['itemname']."','".$_POST['quantity']."','" .$saleprice."')";
  $result = mysqli_query($link,$sql);
  if ($result) {
    header("Location:addbill.php");
  }else{
    echo "error during adding";
  }
}
  • 写回答

1条回答 默认 最新

  • dsds33222 2019-01-29 06:46
    关注

    am not sure why you are using MySQL and mysqli both together, but for your concern, you have to calculate the new sale price before inserting records in database & then insert the calculated sale price instead of an original sale price.

    $intSalesPrice = $saleprice * $_POST['quantity'];
    

    You can calculate new sales prices like this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳