homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
mysq update several rows
helenp

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4407210 posted 8:08 am on Jan 16, 2012 (gmt 0)

Hi,
I have a calendar table wich have rows for 20 years at this moment.
When I add a new property I add dates from present year (now) until year 2032.

The problem is that after I inserted the dates with the name of property I have to update the rows with information as prices, season etc for the choosen dates in all years. So how to do it without having a huge amount of updates?
I dont know a way to do where cal_date beween date1 and date2, and date3 and date4 and date 5 and 6 and property= 'property1' etc.....maybe there is a way.

Also If possible I would like not to change the updatecode, as I can have a multiple selectbox to select years to update, or select several years in diferent boxes etc....the problem is the mysql select, its always best not to touch a working code.

Maybe is possible to do something combining mysql with php to get the years from start of present year until end 2032 and then update the rows those years from php and days and months as choosed in a form.

Donīt know where to start to search how to do it.

Anyway, these are the updates for 2 years for high season, imagine to do it for 20 years.
$query = mysql_query("UPDATE calendar_table SET startdate=2012-07-01, enddate=2012-08-31
WHERE cal_date=2012-07-01 and property='$property2'");
$query = mysql_query("UPDATE calendar_table SET startdate=2013-07-01, enddate=2013-08-31
WHERE cal_date=2013-07-01 and property='$property2'");
$query = mysql_query("UPDATE calendar_table SET price_client='$price_client',
price_owner='$price_owner', price_client_week='$price_client_week',
price_owner_week='$price_owner_week', description='$description', elena='$elena', elena_n='$elena_n', minimo='$minimo'
WHERE cal_date between 2012-07-01 and 2012-08-31 and property='$property2'");
$query = mysql_query("UPDATE calendar_table SET price_client='$price_client',
price_owner='$price_owner', price_client_week='$price_client_week',
price_owner_week='$price_owner_week', description='$description', elena='$elena', elena_n='$elena_n', minimo='$minimo'
WHERE cal_date between 2013-07-01 and 2013-08-31
and property='$property2'");
header ("Location: precios_propiedades_uno.php?property=$property2");


Thanks in advance.

 

helenp

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4407210 posted 12:15 pm on Jan 17, 2012 (gmt 0)

I have this php to get the years from this year until 2032
for($ano = (date("Y")) ; $ano <= 2032; $ano++)
foreach ($ano as $ano2)
{
$llegada = '$ano2-$month-$day';
$salida = '$aņo2-$month2-$day2';

Is it posible to do something similar using this php to update several years at the time (does not work however dont give error either)

$query = mysql_query("UPDATE calendar_table2 SET startdate='$llegada',
enddate='$salida'
WHERE cal_date='$llegada ' and property='$propiedad'");
$query = mysql_query("UPDATE calendar_table2 SET price_client='$price_client',
price_owner='$price_owner', price_client_week='$price_client_week',
price_owner_week='$price_owner_week', description='$description',
elena='$elena', elena_n='$elena_n', minimo='$minimo'
WHERE cal_date between '$llegada' and '$salida' and property='$propiedad'");
$result = mysql_query($query) or die(mysql_error());}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved