0

我有 2 张桌子p_budgetp_services

p_budget包含

id|project_name|budget|source

另一张桌子p_services

id|user|project_name|sdo|transpo|total

我想要一个 php 将添加p_services和减去预算p_budget

我希望你能帮助我完成我的项目:(

4

1 回答 1

1

如果我理解您的意思,您希望从表 1 中取出一个变量,并从表 2 中减去一个变量,对吗?您必须自己学习如何执行此操作才能操作表格,但我将提供一个示例。

//This should start your code, it connects to the db and table.
$connection = mysqli_connect("localhost", "root", "password", "databasename");
mysqli_connect("localhost", "root", "password", "databasename") or die(mysqli_error());

//This gets a single row from the table and lays it out
$query = mysqli_query($connection, "SELECT * FROM p_budget WHERE ID=$IDthatyouarecurrentlyusing");

//Then it pulls one item on the table row out, in this case budget.
$row = mysqli_fetch_assoc($query);
$budget = $row['budget'];

现在,如果您理解这一点,您可以将其复制到另一个表中,然后:

$profit = $budget - $services;
echo $profit;
于 2013-08-10T02:04:27.173 回答