如何将来自不同表但相同数据库 mysqli php 的 2 列相乘
how to Multiply 2 columns from different tables but same database mysqli php
<?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 的 2 列相乘 php
试试这个,它将在 php 中为您提供完整的结果,而无需进行任何操作。
select (quantity* bill) as total from animal inner join price on animal.id=price.animal_id group by price.animal_id;
$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>";
}
在复制和粘贴之前,请检查您的 table 关系列名称并进行相应更新。
<?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 的 2 列相乘 php
试试这个,它将在 php 中为您提供完整的结果,而无需进行任何操作。
select (quantity* bill) as total from animal inner join price on animal.id=price.animal_id group by price.animal_id;
$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>";
}
在复制和粘贴之前,请检查您的 table 关系列名称并进行相应更新。