RE: [PHP-DB] date functions (generates parse error)

2003-03-05 Thread John W. Holmes
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)

2003-03-05 Thread David Rice
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)

2003-03-04 Thread 1LT John W. Holmes
> 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)

2003-03-04 Thread David Rice
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

2003-03-04 Thread 1LT John W. Holmes
> 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



RE: [PHP-DB] date functions

2003-03-04 Thread Hutchins, Richard
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

2003-03-04 Thread 1LT John W. Holmes
> 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



Re: [PHP-DB] Date functions

2002-07-01 Thread [EMAIL PROTECTED]

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