SQL Array

I am trying to pull dates from a database in YYYY-DD-MM format

I have the following code

SORTED

I am not sure I follow… What is not working? Any errors?

I don’t see you pulling anything from a database just creating dates and displaying them and such.

To pull dates the way you want them from a database you will need to look at the DATE_FORMAT() function which is used within the SQL statement itself.

http://www.mysql.com is where you will need to look for this.

Hi Thanks for your reply

Here the db Connection string

[php]

PHP:

<?php require_once('Connections/connect.php'); mysql_select_db($database_connect, $connect); $query = "SELECT * FROM bookings"; $result = mysql_query($query, $connect) or die(mysql_error()); $row_bookings = mysql_fetch_assoc($result); $totalRows_bookings = mysql_num_rows($result); $booking_month =array(); while($row=mysql_fetch_assoc($result)) { $booking_month[]=$row['bookings']; ?>

[/php]

here is where i am attempting to pull the information

[php]

if (strlen($day) == 1) $vday = “0”.$day;
else $vday = $day;
$a_date = date(“Y-m-d”, $days - 86400);
$d_date = date(“Y-m-d”, $days + 86400);
if(in_array($days, $booking_month)){
$arrive = $depart = false; $vtd = “”;
if (!in_array($days, $booking_month)) {
$vtd = “bgcolor=”#9B30FF"";
$arrive = true;
}
if (!in_array($days, $booking_month)){
$vtd = “bgcolor=”#9B30FF"";
$depart = true;
}
if (!$arrive && !$depart){
$vtd = “bgcolor=”#8C1717"";
}
}else{
$vtd = “bgcolor=”#61B329"";
}

[/php]

There are no errors. the tables are showing but the only thing in the code that is happening is

[php]

}else{
$vtd = “bgcolor=”#61B329"";
}

[/php]
This out puts in the table

[php]

><?php echo date($days) ?>

[/php]

Just need someone to look at it and see what I’ve overlooked

I’ve echo the db array and can see all the results

[php]

$go = implode(" “,$booking_month);
echo $go.”
";

[/php]

So something should be happening, I think there may be an error in the following

[php]

<?php $start_day = date('d', mktime(0,0,0,$m,1,$y)); $end_day = date('t', mktime(0,0,0,$m,1,$y)); $weeks = date('w', mktime(0,0,0,$m,0,$y)); ?> <?php for ($days=0;$days<$weeks;$days++) { ?>   <?php } for ($days=1;$days<=$end_day;$days++) { $a_date = date("Y-m-d", $days - 86400); $d_date = date("Y-m-d", $days + 86400); if(in_array($days, $booking_month)){ $arrive = $depart = false; $vtd = ""; if (!in_array($days, $booking_month)) { $vtd = "bgcolor="#9B30FF""; $arrive = true; } if (!in_array($days, $booking_month)){ $vtd = "bgcolor="#9B30FF""; $depart = true; } if (!$arrive && !$depart){ $vtd = "bgcolor="#8C1717""; } } else { $vtd = "bgcolor="#61B329""; } ?>

[/php]

$days is giving the day of the month, when I change its format to date(Y-m-d) its messing the table up but just been a day I dont think it can match itself to anything in the array.

Does anybody know how i would do this

I have had some sort of luck…

By changing

[php]

for ($days=1;$days<=$end_day;$days++) {
$a_date = date(“Y-m-d”, $days - 86400);
$d_date = date(“Y-m-d”, $days + 86400);
if(in_array($days, $booking_month)){
$arrive = $depart = false; $vtd = “”;
if (!in_array($days, $booking_month)) {
$vtd = “bgcolor=”#9B30FF"";
$arrive = true;
}
if (!in_array($days, $booking_month)){
$vtd = “bgcolor=”#9B30FF"";
$depart = true;
}
if (!$arrive && !$depart){
$vtd = “bgcolor=”#8C1717"";
}
}
else
{
$vtd = “bgcolor=”#61B329"";
}

[/php]

to

[php]

$days = date(‘Y-m-d’, mktime(0,0,0,$m,1,$y));
$a_date = date(“Y-m-d”, $days - 86400);
$d_date = date(“Y-m-d”, $days + 86400);
if(in_array($days, $booking_month)){
$arrive = $depart = false; $vtd = “”;
if (!in_array($a_date, $booking_month)) {
$vtd = “bgcolor=”#9B30FF"";
$arrive = true;
}
if (!in_array($d_date, $booking_month)){
$vtd = “bgcolor=”#9B30FF"";
$depart = true;
}
if (!$arrive && !$depart){
$vtd = “bgcolor=”#8C1717"";
}
}
else
{
$vtd = “bgcolor=”#61B329"";
}
for ($days=1;$days<=$end_day;$days++) {

[/php]

What is happening now it the changes are affecting the entire months not the selected dates and this is the line which its coming from

[php]

if (!in_array($days, $booking_month)){
$vtd = “bgcolor=”#9B30FF"";
$depart = true;
}

[/php]

Any suggestions anyone

sry ur code is very confusing. could u ad some comments that may make some things clearer to urself as well.

[php]
// assigns a value like ‘2007-08-01’;
$days = date(‘Y-m-d’, mktime(0,0,0,$m,1,$y));

//runs $days - 86400 = ‘2007-08-01’ - 86400 = -84393;
$a_date = date(“Y-m-d”, $days - 86400);
//$a_date gets something like ‘1969-12-27’

//runs $days + 86400 = ‘2007-08-01’ + 86400 = 88407;
$d_date = date(“Y-m-d”, $days + 86400);
//$a_date gets something like ‘1970-01-07’

//now a date (‘2007-08-01’) gets checked against a variable called $booking_month wich i guess should hold month insise not dates
if(in_array($days, $booking_month))

//the color now is staticly set befor starting the loop

//now $days is just overwritten with the value 1 (it makes the code hard to understand if a variable is used for more than one purpose)
for ($days=1;$days<=$end_day;$days++) {
[/php]

this are the problems i’m running into looking at ur code.

and it makes it hard for me to find out what the code is suposed to do, or where the errors are.

please explain with some comments what a part of ur code is ought to do.
u don’t have to describe every line, but if u wite in there what the next 5 to 10 lines are doing it gets much easier for anyone to understand ur code.

Thnaks for your reply but i’ve sorted it, I used the following

[php]

for ($days=1;$days<=$end_day;$days++) { // sets days in each month
$check = mktime(0,0,0,$m,$days,$y); // check database array for correct date format
$date = date(“Y-m-d”, $check); // checks dates
$a_date = date(“Y-m-d”, $check - 86400); // checks 1st day in array and subtracts 1 day $d_date = date(“Y-m-d”, $check + 86400); // checks last day and adds 1 day

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service