我有以下Mysql表和PHP代碼。我的php循環沒有使用MYsql填充我的數據庫
MySQL:我從Store表中選擇商店的數量。哪個返回我的商店列表。
我也有一個cashup表信息
PHP: 環路會發生這樣的NUMBEROFDAYS被假設是在一個月的日子。
在while循環中,我做了一個SQl select,它根據日期和商店從cashup表中返回我的值。
在循環中我增加了我的日子以允許在我所有的商店中循環31天以返回cashup總和值。
//loop days
$numberofdays = 31;
$monthyear = NOV_2016;
$x = 1;
//loop days
do {
//string days info
$thedate = $x . '_' . $monthyear;
if (strlen($thedate) == 10){
$thedate = '0' . $thedate;
}
//Do select
mysql_select_db($database_localhost, $localhost);
$query_showr = "select sum(cashup_cash) from cashiercashdata where cashup_date LIKE '$thedate' and cashup_store = '$store'";
$showr = mysql_query($query_showr, $localhost) or die(mysql_error());
while ($row_showr = mysql_fetch_assoc($showr))
{
//loop through record rows
foreach($row_showr as $row)
{
///////$insertday = "recon_d" . $x . "_received";
echo " Store : " . $store . " Counter : " . $x . ' : ' . gettype($x) . ' : ' . $row . ' : ' . gettype($row) . '<br>';
mysql_query("
update bankrecon
set recon_d10_received = '$row'
WHERE recon_store = '$store'
and recon_month = '$monthyear'
");
}
}
$x++;
} while ($x <= $numberofdays);
PHP: 環路會發生這樣的NUMBEROFDAYS(整數)假設是在一個月的日子。
在while循環中,我做了一個SQl select,它根據日期和商店從cashup表中返回我的值。
在循環中我增加了我的日子以允許在我所有的商店中循環31天以返回cashup總和值。
此回顯正確顯示我的信息,但我的循環更新只在numberofdays設置爲靜態10時才插入信息;
Store : centralpark Counter : 10 : integer : 56277.40 string
Store : ficksburg Counter : 10 : integer : 42698.14 string
Store : kroonstad Counter : 10 : integer : 28486.70 string
Store : maitland Counter : 10 : integer : 55988.40 string
Store: od Counter : 10: integer 41412.10 string
它在顯示上正常工作,但不更新目標表。 任何人都可以請向我解釋爲什麼numberofdays信息的循環不會觸發列的更新,但如果numberofdays是靜態更新。現在
打印SQL查詢,你會得到錯誤。 –
不幸的是,打印sql和回顯值給出了相同的結果。信息與這些值正確對應。意思是我的查詢是正確的。內循環中的更新會正確更新目標表,但前提是numberofdays var將設置爲static 10 int。使用while循環或for循環的動態更改值的迭代會導致update語句不能正確響應 –