我試圖運行PHP這些查詢到MySQL表從多個表PHP選擇並添加值一起獲得總
$sql="SELECT * from customer where customerid > '' and voicemail_max > '' and company_status = '' ";
$rs=mysql_query($sql,$conn);
while($customer=mysql_fetch_array($rs)) {
$sql2="SELECT * from client where parent_client_id = '".$customer["customerid"]."' ";
$rs2=mysql_query($sql2,$pbx01_conn);
while($result2=mysql_fetch_array($rs2))
{
$sql3="SELECT * from extension where client_id = '".substr($result2["id"],1,3)."' ";
$rs3=mysql_query($sql3,$pbx01_conn);
while($result3=mysql_fetch_array($rs3))
{
$sql4="SELECT * from extension_voicemail where extension_id = '".$result3["id"]."' ";
$rs4=mysql_query($sql4,$pbx01_conn);
$voicemail_size_total=0;
while($result4=mysql_fetch_array($rs4)) {
$voicemail_size_total = $voicemail_size_total+$result4["filesize"];
}
}
}
echo $voicemail_size_total;
}
應該從一列
加總多個值$sql4
查詢看起來像:
SELECT * from extension_voicemail where extension_id = '1454'
當我運行在數據庫中,它與文件大小列返回一行爲31780
但是當我回顯$voicemail_size_total
變量時,它什麼都沒顯示。
它工作正常,如果我贊同從那裏是可變的一條線,但它現在是顯示什麼