gpt4 book ai didi

PHP 多数组循环 WHERE 子句

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:47 25 4
gpt4 key购买 nike

嘿伙计们,我想通过在循环或其他内容中更改此语句来重复此语句 13 次。 "WHERE spending.SectorID = 1,2,3,4,5,6,7,8,9,10,11,12,13" 我怎样才能在不输入此代码的情况下成功完成 12更多次。不过我会单独显示数据~比如where sectorid = 1; 属于一个带有启动该特定查询的按钮的表

<?php
$spendingname= array();
$spendingpercent = array();
$spendingid = array();

mysql_select_db($database_conn2, $conn2);
$query_Spending = "SELECT CONCAT(spending.SectorID, spending.ExpenditureID) AS 'SpendingID',
expenditure.ExpenditureName, spending.SpendingPercent, spending.SectorID
FROM spending
INNER JOIN expenditure ON spending.ExpenditureID = expenditure.ExpenditureID
WHERE spending.SectorID = 1";
$Spending = mysql_query($query_Spending, $conn2) or die(mysql_error());
$totalRows_Spending = mysql_num_rows($Spending);
while($row_Spending = mysql_fetch_assoc($Spending))
{
$spendingname[] = $row_Spending['ExpenditureName'];
$spendingpercent[] = $row_Spending['SpendingPercent'];
$spendingid[]= $row_Spending['SpendingID'];
}
mysql_free_result($Spending);
?>

最佳答案

    <?php
$spendingname= array();
$spendingpercent = array();
$spendingid = array();

mysql_select_db($database_conn2, $conn2);
for($x=1;$x<14;$x++)
{
$query_Spending = "SELECT CONCAT(spending.SectorID, spending.ExpenditureID) AS 'SpendingID',
expenditure.ExpenditureName, spending.SpendingPercent, spending.SectorID
FROM spending
INNER JOIN expenditure ON spending.ExpenditureID = expenditure.ExpenditureID
WHERE spending.SectorID = $x";
$Spending = mysql_query($query_Spending, $conn2) or die(mysql_error());
$totalRows_Spending = mysql_num_rows($Spending);
while($row_Spending = mysql_fetch_assoc($Spending))
{
$spendingname[$x] = $row_Spending['ExpenditureName'];
$spendingpercent[$x] = $row_Spending['SpendingPercent'];
$spendingid[$x]= $row_Spending['SpendingID'];
}
mysql_free_result($Spending);
}

//To access and print all elements.
for($x=1;$x<count($spendingname);$x++)
{
echo "The value for query $x";
echo $spendingname[$x]." ".$spendingpercent[$x]." ".$spendingid[$x]."<br><br><br>";
}

?>

关于PHP 多数组循环 WHERE 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8731504/

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