RE: [PHP-DB] date functions (generates parse error)
This is very weird. What are you using to create this code? If you remove all of the spaces (?) before $query, the code doesn't give a parse error. It shouldn't give one either way, though, if those are spaces or a tab before your $query = ... line. Even if you remove all of the text and only leave , and those "spaces", PHP will spit something like: Notice: Use of undefined constant - assumed ' ' in c:\inetpub\wwwroot\test.php on line 3 So, the fix is to remove those characters and replace them with spaces or tabs. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -Original Message- > From: David Rice [mailto:[EMAIL PROTECTED] > Sent: Wednesday, March 05, 2003 12:34 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: Re: [PHP-DB] date functions (generates parse error) > > > Sorry, I forgot to add the part at the bottom where I am calling the > function > > = > > function tips($weekstart){ > > $start = date('Ymd',strtotime($weekstart)); > > $query = "SELECT * FROM Rota WHERE date >= $start and date <= > ($start + > INTERVAL 6 DAY) ORDER BY staffid"; > $result = mysql_query($query); > while ($row = mysql_fetch_array($result)){ > > if ( isset ( $tips ) ){ > > if (isset ( $tips[$row[staffid]] ) ){ > > $hours = $row[finish] - $row[start]; > $tips[$row[staffid]] = $tips[$row[staffid]] + > $hours; > > } > > else{ > > $tips[$row[staffid]] = $row[finish] - $row[start]; > > } > } > > else{ > > $tips = array('$row[staffid]' =>( $row[finish] - > $row[start] ) ); > > } > > } > > return $tips; > > } > > function dbconnect(){ > mysql_connect("localhost", "filterseveuk", "godisadj"); > mysql_select_db("filterseveuk"); > } > > dbconnect(); > $date = "2003-03-02"; > > var_dump(tips($date)); > ?> > > _ > Express yourself with cool emoticons http://messenger.msn.co.uk > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions (generates parse error)
Sorry, I forgot to add the part at the bottom where I am calling the function = $start = date('Ymd',strtotime($weekstart)); $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ORDER BY staffid"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ if ( isset ( $tips ) ){ if (isset ( $tips[$row[staffid]] ) ){ $hours = $row[finish] - $row[start]; $tips[$row[staffid]] = $tips[$row[staffid]] + $hours; } else{ $tips[$row[staffid]] = $row[finish] - $row[start]; } } else{ $tips = array('$row[staffid]' =>( $row[finish] - $row[start] ) ); } } return $tips; } function dbconnect(){ mysql_connect("localhost", "filterseveuk", "godisadj"); mysql_select_db("filterseveuk"); } dbconnect(); $date = "2003-03-02"; var_dump(tips($date)); ?> _ Express yourself with cool emoticons http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions (generates parse error)
> Here is the whole code of my function > > Whenever i run it, it say's there is a parse error on line 6, can't see what > is the problem > the format of $weekstart (as it is stored in the Database) is -MM-DD > > = > function tips($weekstart){ > > $start = date('Ymd',strtotime($weekstart)); > > $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + > INTERVAL 6 DAY) ORDER BY staffid"; > $result = mysql_query($query); > while ($row = mysql_fetch_array($result)){ > > if ( isset ( $tips ) ){ > > if (isset ( $tips[$row[staffid]] ) ){ > > $hours = $row[finish] - $row[start]; > $tips[$row[staffid]] = $tips[$row[staffid]] + $hours; > > } > > else{ > > $tips[$row[staffid]] = $row[finish] - $row[start]; > > } > } > > else{ > > $tips = array('$row[staffid]' =>( $row[finish] - $row[start] ) ); > > } > > } > > return $tips; > > } I cut and pasted your exact code here and didn't get a parse error. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions (generates parse error)
Here is the whole code of my function Whenever i run it, it say's there is a parse error on line 6, can't see what is the problem the format of $weekstart (as it is stored in the Database) is -MM-DD = $start = date('Ymd',strtotime($weekstart)); $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ORDER BY staffid"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ if ( isset ( $tips ) ){ if (isset ( $tips[$row[staffid]] ) ){ $hours = $row[finish] - $row[start]; $tips[$row[staffid]] = $tips[$row[staffid]] + $hours; } else{ $tips[$row[staffid]] = $row[finish] - $row[start]; } } else{ $tips = array('$row[staffid]' =>( $row[finish] - $row[start] ) ); } } return $tips; } _ Stay in touch with absent friends - get MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions
> I want to use it in this function that i am creating (it's for a resteraunt > automated tips system, to work out how much tips each staff member is > entitled to. > > > function tips($weekstart){ > /* JUST BELOW HERE IS WHERE I NEED TO GET THE DATE OF 6 > DAYS AFTER THE > SPECIFIED DATE OF THE START OF THE WEEK */ > $weekend = date($weekstart +6); > > $query = "SELECT * FROM Rota WHERE date => $weekstart > AND date <= $weekend ORDER BY staffid"; > > etc... What format is $weekstart in? Maybe you said already, I can't remember. You could try $weekend = strtotime($weekstart . ' +6 days'); Since I think your 'date' column is a TIMESTAMP, you'll need to format $weekstart and $weekend as MMDD in order to get what you have above to work. Maybe try this: function tips($weekstart){ $start = date('Ymd',strtotime($weekstart)); $query = "SELECT * FROM Rota WHERE date >= $start and date <= ($start + INTERVAL 6 DAY) ORDER BY staffid"; etc... ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] date functions
I want to use it in this function that i am creating (it's for a resteraunt automated tips system, to work out how much tips each staff member is entitled to. function tips($weekstart){ /* JUST BELOW HERE IS WHERE I NEED TO GET THE DATE OF 6 DAYS AFTER THE SPECIFIED DATE OF THE START OF THE WEEK */ $weekend = date($weekstart +6); $query = "SELECT * FROM Rota WHERE date => $weekstart AND date <= $weekend ORDER BY staffid"; etc... _ Surf together with new Shared Browsing http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] date functions
Good stuff here. http://www.mysql.com/doc/en/Date_and_time_functions.html Check out the SELECT DATE_ADD section. That might be what you're looking for. HTH, Rich > -Original Message- > From: David Rice [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 04, 2003 9:36 AM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] date functions > > > > > I am looking for a way to take a date stored in a mysql > database... and find > out the date seven days later. > > how would i do this?! > > > cheers, dave > > > > _ > Chat online in real time with MSN Messenger http://messenger.msn.co.uk > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] date functions
> I am looking for a way to take a date stored in a mysql database... and find > out the date seven days later. > > how would i do this?! too easy... SELECT date_column + INTERVAL 7 DAY FROM your_table ... ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] date functions
I am looking for a way to take a date stored in a mysql database... and find out the date seven days later. how would i do this?! cheers, dave _ Chat online in real time with MSN Messenger http://messenger.msn.co.uk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Date functions
On Mon, 1 Jul 2002, Achilleas Maroulis wrote: > Hi. > I want to know what is the right way to make some comparisons with date variables. > I have used only the date() function to get a variable in this format=> 01-07-2002 > Is there a way to add 20 days in order to have 21-07-2002 or 2 months to have >01-09-2002? Hi! Try to read PHP documentation: http://www.php.net/manual/en/function.mktime.php Regards Urosh -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Date functions
Hi. I want to know what is the right way to make some comparisons with date variables. I have used only the date() function to get a variable in this format=> 01-07-2002 Is there a way to add 20 days in order to have 21-07-2002 or 2 months to have 01-09-2002? Thanx in advance...
[PHP-DB] DATE FUNCTIONS
I'm having problems using SQL date functions with ODBC (unix). I've browsed endless mailing lists and manuals but things that seem to work for other people doesn't work on my setup. I can get my IF statement in php working, but really need to have the validation in the select statement. Other date functions like WEEKDAY() doesn't work either. My statements are something like select * from menuyr where meal_dte = DATE("02/15/2001") and select * from menuyr where WEEKDAY(meal_dte) = 2 They both give the same error: Warning: SQL error: [unixODBC][OpenLink][ODBC][Driver]Option Value Changed, SQL state [Ã÷Ø in SQLExecDirect in /www/data/isdmeals/ru_diet.php on line 73 Line 73 would be the odbc_exec() statement. Am I doing something totally stupid or is their some kind of library to be included for these functions to work? Oh, and another thing is if I run the exact same select statement on the database directly - it works! Hope someone can help... Lynnette Klackers -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]