Thursday 15 April 2010

php - Inserting range of dates in mysql db -


I have a mysql database in which I am trying to put a continuous date for one year (7-1-2012) ) And only want the date of the week using Fridays. I have the code given below but get an error message: "values ​​(date (" Ymd ", $ i)" on line 11 Unexpected 'Y' (T_String). Any help is greatly appreciated. $ startdate = mktime (0,0,0,7,1,2013); $ A Ndet = Strootomat ("+ 1 year", $ startdate); // Now we have less number and one is upper // number, we can loop to give dates $ startdate echo; $$ i = $ startdate; For $ i & lt; = $ enddate; $ i = strtotime ("+ 1day", $ i)) {if ($ I> = 2 & amp; $ i & lt; = 6) {$ insert_query = "Include in ShadowStats (Shade-date, Sherip, Repeedy) value (date (" YMD ", $ i), 2," All Day ")" Mysql_query ($ insert_query) or die ("Error in query: $ insert_query ".mysql_error ());}}

Ddharn contrast in style must use quotes style, or avoid citations, such as \ " or \ ', within a string. You should also use MySQL's date and time function as MySQL. $ Insert_query = "Insert int o shadstat (shade-date, shadowp, rik.pod) value (date (" y-m-d ", $ i), 2," all day "); Something like this should be:

  $ insert_query = "INSERT shadtsat (shade-date, Sherip, rakopyodi) value (DATE_FORMAT (FROM_UNIXTIME ($ i), '% Y-% m-% d' ), 2, 'all day') ";   

See for more information.

Side note: # Variables, such as $ i , will be evaluated within double quotation marks. Single dimensional anmeric arrays can also be evaluated in double quotes, such as "what $ eri [1] more information here"; . If you want to put a single dimensional associative array in double quotation marks, then it may be "what {$ ary ['key']} more information here;"; If you are putting another string inside the string, think that the string that is being tampered with in your quotation marks, so if the quotes themselves need to be in the string, then you Put them in the string, put them back if you can not get your results through any dual bidding methods, then use concatenation, such as ' What ' $ Ary [0] ['key'] More info here '; Since PHP will examine and evaluate everything inside double quotes because it can be technically faster to use the same quotation marks. I use double quotes at all times and it works fine, though.

No comments:

Post a Comment