【问题标题】:how to Multiply 2 columns from different tables but same database mysqli php [closed]如何将来自不同表但相同数据库mysqli php的2列相乘[关闭]
【发布时间】:2018-09-05 15:20:48
【问题描述】:
<?php

$con = mysqli_connect("localhost", "root", "", "zoo");

if (mysqli_connect_error()) {
    echo "Failed to connect" . mysqli_connect_error();
}

$sel = "Select * from animal where quantity";

$result = mysqli_query($con, $sel);

while ($row = mysqli_fetch_array($result)) {

    echo "<tr>";
    echo"<td>" . $row['quantity'] . "</td>";
}
$qsel = "Select * from price where bill";
$result = mysqli_query($con, $qsel);
while ($row = mysqli_fetch_array($result)) {

    echo "<tr>";
    echo "<td>" . $row['bill'] . "</td>";
}
?>

如何将来自不同表但相同数据库 mysqli php 的 2 列相乘

【问题讨论】:

标签: php mysql multiplication


【解决方案1】:
$con = mysqli_connect("localhost", "root", "", "zoo");

if (mysqli_connect_error()) {
    echo "Failed to connect" . mysqli_connect_error();
}

$sel = "select (quantity* bill) as total from animal inner join price on animal.id=price.animal_id group by price.animal_id";
$result = mysqli_query($con, $sel);
while ($row = mysqli_fetch_array($result)) {

    echo "<tr>";
    echo"<td>" . $row['total'] . "</td>";
}

在复制和粘贴之前检查您的表关系列名称并相应更新。

【讨论】:

  • 不要发布多个答案。您可以编辑您的答案以进行修改
  • 好的。 @B.Desai 为您提供建议。
  • @buttercup。这就是为什么我告诉检查两个表中的关系列。把两个表结构都寄给我。我帮你查询。
  • 只需在此处粘贴表格和列。
  • @buttercup tam 谈论列名。
【解决方案2】:

试试这个,它会给你整个结果,而无需在 php 中进行操作。

select (quantity* bill) as total from animal inner join price on animal.id=price.animal_id group by price.animal_id;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多