この質問に正しく名前を付ける方法がわからないため、必要に応じて自由に編集してください。
月に1つずつ12個のボックスがあり、各ボックスには次のように表示されます。1-データベースからの情報に応じて、「販売済み」または「利用可能」などのメッセージ。2-月と年の名前。月が現在の月よりも古い場合、年は1つ増えます。
データベースからの情報には、|で区切られたいくつかの値があります。シンボル、チェックする適切なものはlasのものであり、$row['custom']の値の例は次のとおりです。夕食| 新しいポート| 2012年8月
私の問題は、各ボックスを「ステータス」で更新する必要があり、現在のスクリプトでは、データベースのlasエントリのみがボックスの更新に使用されるため、2つ以上のボックスを表示する必要があることがわかっている場合メッセージ「販売済み」、最新のもののみが更新されます。
次のスクリプトを変更して、ボックスを1つずつ更新するにはどうすればよいですか?問題は、データベースまたは他の何かをクエリする方法ですか?
ヘルプやアドバイスを事前に感謝します。
物事を短くするために、12か月のうち2か月だけコーディングする
<?php
$month = date("m"); // Current month
$year = date("Y"); // Current year
$next = strtotime(date("d-m-Y", strtotime($now)) . "+1 year");
$nextyear = date("Y", $next); // Next year
// Check if this month is gone or not, if gone replace current year with next year
$january = "01";
$february = "02";
if ($month > $january) {
$jan = 'January - ' . $nextyear; } else { $jan = 'January - ' . $year;}
if ($month > $february) {
$feb = 'February - ' . $nextyear; } else { $feb = 'January - ' . $year;}
//Get info from Database
$query = "SELECT `custom` FROM `payments` WHERE `status` = 'Pending' OR `status` = 'Completed'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$check_custom = explode(" | ", $row['custom']);
$month_sold = $check_custom[3];
}
// Check if month is sold or not
if ($month_sold == $jan) { $jan_status = 'Sold';} else { $jan_status = 'Available';}
if ($month_sold == $feb) { $feb_status = 'Sold';} else { $feb_status = 'Available';}
//Output the months and their status
?>
<div class="month">
<div class="mname"><?php echo $jan;?></div>
<div class="<?php echo $jan_status;?>">
<?php echo $jan_status;?>
</div>
<?php if($jan_status == 'Available') {
echo 'This month is ' . $jan_status . '.';
} else {
echo 'This month has been ' . $jan_status . '.';} ?>
</div>
<div class="month">
<div class="mname"><?php echo $feb;?></div>
<div class="<?php echo $feb_status;?>">
<?php echo $feb_status;?>
</div>
<?php if($feb_status == 'Available') {
echo 'This month is ' . $feb_status . '.';
} else {
echo 'This month has been ' . $feb_status . '.';} ?>
</div>