2015-02-24 44 views
0

列名PHP PDO的代码与日期

优惠券

coupondate

STARTINGDATE

我基于优惠券和STARTINGDATE产生coupondate没有追加。

FOR EX -

如果券= 500501和STARTINGDATE = 24-02-2015

然后coupondate产生象下面..

coupondate = 23-03-2015,23- 04-2015

但我需要追加优惠券与coupondate

FOR EX -

500 - 23-03-2015

501 - 23-04-2015喜欢聪明..

PLZ帮助来获得上述输出

低于

是我的代码

$coupon = $_POST['coupon'];       
        $startingdate = $_POST['startingdate'];       
        $coupons = explode(',', $coupon);      
        $dates = Array(); 
        for ($no = 1; $no < count($coupons) + 1; $no++) 
        { 
        $dates[] = date("d-m-Y", strtotime($startingdate . " +" . $no . " MONTHS -1 DAYS"));       
        }      
        $coupondate = implode(',', $dates); 
+0

你能加$ _ POST值[“优惠券”] – 2015-02-24 09:09:23

+0

是的,这也将在数据库中,但在seprate列.... – 2015-02-24 09:16:00

+0

我需要追加$ _ POST [“优惠券”] - 用每个日期 – 2015-02-24 09:17:01

回答

0

尝试foreach而不是for循环,并附加优惠券代码以及日期。

$coupon = $_POST['coupon']; 
$startingdate = $_POST['startingdate']; 
$coupons = explode(',', $coupon); 
$dates = Array(); 
$no = 1; 
foreach($coupons as $coupon) { 
    $dates[] = $coupon . " - " . date("d-m-Y", strtotime($startingdate . " +" . $no . " MONTHS -1 DAYS")); 
    $no++; 
} 
$coupondate = implode(',', $dates); 

echo "<pre>"; 
print_r($coupondate); //out put you required 
echo "</pre>"; 
+0

非常感谢谢谢......它的工作,但后你的代码中的一些变化.....我改变$ coupons = $ _POST ['coupon'];到这个$ coupon = $ _POST ['coupon']; – 2015-02-24 09:38:01

+0

是的,谢谢你,我编辑了我的代码。 – 2015-02-24 09:39:36