简体   繁体   English

使用php将一个表数据与其他表数据分开

[英]divide one table data from other table data using php

I had tried to display the divided value of saleprice from the table (additem) and from the table (addbill) data .iequantity that we entered in the addbill table and display the value in the price column in addbill table. 我曾试图从表中(的AddItem),并从我们在addbill表中输入表(addbill)数据显示.iequantity的saleprice分割值和addbill表显示在价格列中的值。

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";
  }
}

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. 不确定为什么要同时使用MySQL和mysqli,但是出于您的考虑,您必须在将记录插入数据库之前计算新的销售价格,然后再插入计算出的销售价格而不是原始销售价格。

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

You can calculate new sales prices like this. 您可以像这样计算新的销售价格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM