gpt4 book ai didi

php - 有没有一种方法可以创建一个 while 循环来动态仅获取大于 0 的值并打印字段和值?

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

// Connect to server and select databse.
$conn = mysqli_connect("$host", "$username", "$password")or die("cannot connect");
mysqli_select_db($conn,"$db_name")or die("cannot select DB");

here i am selecting all data from the database

$sql = "SELECT * FROM $tb2_name WHERE Month='$month' AND Year='$year' AND Employee_Number='$user'";
$result = $conn->query($sql);


// output data of each row
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
$Tax_Num = $row['Tax_Number'];
$Number = $row["Employee_Number"];
$Payslip_Number = $row["Payslip_Number"];
$Salary = $row["Salary"];
$Bonus = $row["Bonus"];
$Housing_Allowance = $row["Housing_Allowance"];

当在数据库中动态创建列时会出现问题,因此无法手动定义列。

有没有办法创建一个 while 循环来动态仅获取大于 0 的值?

最佳答案

不完全确定您想要在这里实现什么,但也许您认为这种方式太困难了。你的意思是这样吗?

$sql = "
SELECT
*
FROM
$tb2_name
WHERE
Month='$month'
AND
Year='$year'
AND
Employee_Number='$user'
";

$result = mysqli_query($conn, $sql);
$rows = mysqli_fetch_assoc($result);

$data = array();
foreach($rows as $key => $value) {
if($value > 0) {
echo $key . " => " . $value . "\n";
}
}

#In $data there will be only database column values which are bigger than 6..
#Mmmm... still sounds like a strange request to me...
#Perhaps I interpreted your question wrong

关于php - 有没有一种方法可以创建一个 while 循环来动态仅获取大于 0 的值并打印字段和值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36040417/

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