Not sure how to name correctly this question so feel free to edit if is needed.
I have 12 boxes one per month, and each box display:
1 – A message like “Sold” or “Available” depending on the info coming from the database.
2 – The name of the month and the year, if the month is older than the current month the year will be increased by one.
The info coming from the database have a few values separated by a | symbol, the pertinent one to check is the las one, an example value of $row[‘custom’] is: 93 | Supper | New Port | August – 2012
My problem is that I need to update each box with their “status” and with the current script only the las entry on the database is used to update the boxes, so In cases where i know there is two or more boxes that should display the message “Sold”, only the most recent is the updated.
How can I modify the following script to update one by one box ?
The problem is the way I’m querying the database or something else ?
Thanks in advance for any help or advice.
Code only for 2 of 12 month, to make things short
<?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>
You misplaced the closing bracket of while and move the `$jan_status=’Available’ from inside while loop to just above it; Here is the modified code