2016-01-04 42 views
0

我已經創建了生成pdf發票的腳本,腳本基於FPDF庫。我沒有問題爲單個帳戶創建發票,但是如何爲多個帳戶運行它。我通過curl傳遞賬號,​​,在xyz.php我以$ account = $ _POST ['account']開頭; ,其中所有其他sql查詢都是爲給定帳戶執行以收集數據。腳本'取得'只有最後一個帳號並將發票保存到文件中。如何爲多個帳戶運行發票生成器?

我能夠將100個帳戶傳遞給生成器,但我不知道,如何爲每個帳戶運行100次腳本。

我試着用foreach,但它不適合我。

+0

我建議使用PHP腳本的命令行訪問,而不是捲曲:'PHP /Path/To/xyz.php 1 2 3 ... 99 100'。您需要更改腳本以接受命令行參數 – binnyb

回答

0

你可以使用一個for循環:

for($i = 1; $i <= 100; $i++){ 
    /* $i will increase from 1 to 100, so you can 
    curl to http://localhost/xyz/xyz.php?account=$i */ 
} 

另外,用分離器發送GET變量,如:

//localhost/xyz/xyz.php?account=1,3,5,10 

xyz.php頁面,您可以做一個上通過它們循環如下:

//make $accounts an array of the account values 
$accounts = explode(",", $_GET["account"]); 

foreach($accounts as $account){ 
    //$account will be each value processed, e.g. 1, 3, 5, 10 etc 
} 
1

您正在覆蓋您的參數。你應該將它們作爲一個數組:account[]=1&account[]=2,然後遍歷$_GET['account']做你想做什麼:

foreach ($_GET['account'] as $account_id) { 
    // generate invoice... 
}