Forum Moderators: coopster

Message Too Old, No Replies

insert several variables mysql

         

helenp

12:31 pm on Dec 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,
I need to do an workaround for my availabilitychart, though I donīt have mysql 4.1,
and one way is having all the dates as columnnames in an table with an value, and when getting an booking update the columns that are booked with another value.

So I have this script that figures out the dates between two dates:
(the strtotime donīt know if correct, I added it trying to take the mysql format in the variable.)

//start date 2004-12-10
$sm=12;
$sd=10;
$sy=2004;

//end date 2004-12-14
$em=12;
$ed=14;
$ey=2004;

//utc of start and end dates
$s=mktime(0,0,0,$sm, $sd, $sy);
$e=mktime(0,0,0,$em, $ed, $ey);

while($s<=$e){
print date('Y-m-d',$s).","; //display date in mySQL format
(strtotime ("%Y-%m-%d",$s=$s+86400)); //increment date by 86400 seconds(1 day)

Then the problem, how to update all the columns that have the dates I just received?
The update would be like this:
$sql = mysql_query("UPDATE `disponibilidad` SET `$s` = 'z' WHERE `property` = 'Banana_Beach_3' ");

I need to put all dates into the variable $s in the query.

helenp

11:52 pm on Dec 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



nobody, please,
at least help which way to go...

coopster

2:58 am on Dec 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't follow yet, helenp. Based on the query you requested, it might look something like...
UPDATE `disponibilidad` SET `2004-12-10` = 'z' 
WHERE `property` = 'Banana_Beach_3';
Can you give a more detailed explanation of what you want to accomplish?

helenp

9:04 am on Dec 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks,
Well In the loop I get the dates that are between startdate and enddate, until here perfect.

In mysql I have an table with dates as name of the columns with an value, so
now I need to update all columns with same name as the dates I got in the loop.

This needs to be done automatically,
so the query must be:
$sql = mysql_query("UPDATE `disponibilidad` SET `$s` = 'z' WHERE `property` = 'Banana_Beach_3' ");

Now I think I am stupid, that putting the query inside the loop like this:
while($s<=$e){
etc,
here the update query
}

and that would do it....?
I tried it but I do think the format is wrong with the dates, need to be converted to mysql format date #*$!x-xx-xx