<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("cannot connect" . mysql_error());
}
mysql_select_db("test",$con);
$sql = "SELECT Renewal_Date FROM ilist";
$mydata = mysql_query($sql,$con);
$result_array = array();
echo "<table border=2 >
<tr>
<th>Renewal_Date</th>
</tr>";
while($record = mysql_fetch_array($mydata)){
echo"<tr>";
echo "<td>" . $record['Renewal_Date'] . "</td>";
echo "</tr>";
}
echo "</table>";
$date3=array();
$todayDate = date('m/d/Y');
$date1 = new DateTime($todayDate);
$date2 = new DateTime($record['Renewal_Date']);
foreach($date2 as $date3)
$interval = $date1->diff($date3);
echo "difference " . $interval->y . " years, " . $interval->m." months, ".$interval->d." days ";
mysql_close($con);
?>
我已經取續約日期列表到一個數組$紀錄,現在我需要使用的foreach到每個日期存儲在 一個變量,這個變量將是用於查找與當前日期的差異。 如何做到這一點?如何使用foreach循環到一個變量在PHP存儲陣列日期
regards Sanji
什麼錯誤?什麼不起作用? – Hussain
格式不匹配錯誤在那裏。尚卡達摩達蘭的回覆工作正常。謝謝 – sanjisanjy