2016-12-14 58 views
0
<?php 
session_start(); 
?> 
<?php error_reporting(0); ?> 
<?php 
    session_start; 
    include("includes1/db.php"); 
    include("includes1/functions1.php"); 
    $_SESSION ["cart"]++; 
    if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){ 
     $pid=$_REQUEST['productid']; echo"$pid"; 
     addtocart($pid,1); 
     header("location:product_summary1.php"); 
     exit(); 
    } 

?> 
<html> 
<body> 
<?php 
mysql_connect("localhost","root","") or die("Demo is not available, please try again later"); 
mysql_select_db("agriculture") or die("Demo is not available, please try again later"); 

if (!empty($_GET['sort']) && $_GET['sort'] == 'PriceAsc') { 
    $orderby=" ORDER BY price ASC"; 
} 
if (!empty($_GET['sort']) && $_GET['sort'] == 'PriceDesc') { 
    $orderby=" ORDER BY price DESC"; 
} 
?> 
<div class="row-fluid"></div> 
<ul class="thumbnails"> 
<?php 
$datestart = '15-12-2016'; 
$dateend = '16-12-2016'; 
$product_name= 'product_name'; 
$discount= 'discount'; 
$price = 'price'; 
$data=mysql_query("select * from promotion ".$orderby) or die("select * from promotion"."<br/><br/> 
".mysql_error()); 
while($row=mysql_fetch_array($data)){ 
?> 

<li class="span3"> 
<div class="thumbnail"> 

<a href="product_details.html"><img src="themes/images/products/<?php echo $row['productimage']?>" alt=""/></a> 
<div class="caption"> 
<h5><?php echo $row['name']?></h5> 
<h5>PROMOTION END : <?php echo $row['dateend']?></h5> 
<p>&nbsp;</p> 

<h4 style="text-align:center"></i></a> <a class="btn" type="button" value="Add to Cart" onClick="addtocart(<?php echo $row['serial']?>)">Add to <i class="icon-shopping-cart"></i></a> 
<a class="btn btn-primary" href="#">RM <?php $date = date ('d-m-y'); 
    if ($date <= $datestart) 
    {echo $total = $row['price'] - $row['discount']."</br>" ;} 
    else if ($date <= $dateend) 
    {echo $row['price'] ."<br/>";} 
    else 
    {echo $row['price']."<br/>"; 
    }?></a> /unit</h4> 

</div> 
</div> 
<?php } ?> 

</li> 
</ul> 


</form></div> 
</div> 
</div> 
</div> 
</body> 
</html> 

這是我的促銷頁面代碼。我必須使用我填入數據庫的日期。當促銷日期到期時,價格必須在促銷前變爲價格。所以我創建了我聲明日期提升並使用它的函數。但是當促銷日期結束時,價格顯示會發生變化。但是當我點擊添加到購物車時,價格是以促銷價格。不是標準價格。幫助幫助我。如何從mysql使用php /動態價格獲取促銷日期

+0

使用的mysqli。 mysql_ ..的所有函數都已折舊。 –

+0

我不知道如何使用mysqli。 tmrw我的演講日。我沒有太多時間研究它。你可以幫助我嗎:(:( –

回答

0

嘗試改變date ('d-m-y')date ('d-m-Y')

+0

我已嘗試但它不工作。 –

+0

嘗試'echo $ date'並更改 – weirdo

+0

更改'$ datestart = date('dm-Y',strtotime('15 -12-2016 ')); $ dateend = date('dm-Y',strtotime('16 -12-2016'));' – weirdo