gpt4 book ai didi

php - 如何在不同的表中获得减号和加号

转载 作者:行者123 更新时间:2023-11-29 13:40:25 27 4
gpt4 key购买 nike

我有 2 个表 p_budgetp_services

p_budget 包含

id|project_name|budget|source

另一个表p_services

id|user|project_name|sdo|transpo|total

我想要一个能够添加 p_services 并减去 p_budget 中的预算的 php。

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

最佳答案

如果我理解你的意思,你想要从表 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;

关于php - 如何在不同的表中获得减号和加号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18157940/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com