Re: [PHP] Forms & PHP

2003-07-02 Thread Greg Wiley
On Wed, 2 Jul 2003 14:45:27 +0100, Gary Ogilvie <[EMAIL PROTECTED]> 
wrote:

[snip]
By maintaining the POST (assuming you're using POST)variables and
calling them into the form values when reloaded. If you go to the second
page store the POST variables in hidden form input types, then grab them
when the second page is POSTED. Does this make sense? Not enough
caffeine for me yet...[/snip]
So basically I need to have 2 versions of the first page, is that right?
:)

No, in your first form you have code like

;
 } else {
$foo = $_POST['foo'];
 }
?>

 
 ...

and in the second form you have:


 
 ...

Cheers, Greg.
--
Greg Wiley
www.wileysworld.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Forms & PHP

2003-07-03 Thread Greg Wiley
On Wed, 02 Jul 2003 14:58:39 +0100, Greg Wiley <[EMAIL PROTECTED]> 
wrote:

On Wed, 2 Jul 2003 14:45:27 +0100, Gary Ogilvie 
<[EMAIL PROTECTED]> wrote:

[snip]
By maintaining the POST (assuming you're using POST)variables and
calling them into the form values when reloaded. If you go to the second
page store the POST variables in hidden form input types, then grab them
when the second page is POSTED. Does this make sense? Not enough
caffeine for me yet...[/snip]
So basically I need to have 2 versions of the first page, is that right?
:)

No, in your first form you have code like

Well almost. I realised whilst trying to get to sleep last night that 
there's a problem with this. In the first form you need:

;
	$action = "form2.php";
} else {
$foo = $_POST['foo'];
	$action = "results.php";
}
?>


...

This way you won't get a circular dependency. However, it means that you'll 
need to provide some other way of amending the details on form2 if it's a 
requirement.

and in the second form you have:



...

Cheers, Greg.
--
Greg Wiley
www.wileysworld.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] PCRE regexp bug ?

2003-08-15 Thread Greg Wiley
- Original Message - 
From: <[EMAIL PROTECTED]>
>
> I use preg_match to validate the Middle Initial field of a form and so far
> it works, except yesterday a user submitted a "0" (zero) as a middle
> initial!  My regexp is:
>
> if (!empty($_POST[MI]) && (preg_match('/^[[:alpha:]]{1,1}$/', $_POST[MI])
== 0))
>
> I tested it with 0-9 and my regexp catches every digit except 0.
Curious...
>
Maybe it thinks it's the letter O, have you tried using a font that puts a
line through the zero;-)

[sorry couldn't resist]

Cheers, Greg.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] How many Mondays in a month?

2003-09-29 Thread Greg Wiley
Funny you should ask this because I've been meaning to share some code that
I wrote a few months ago that does exactly this for any day of the week.

Please feel free to use this and make changes. I'd appreciate any
changes/bug fixes being sent back to me though.

 "Monday",
   "Tue" => "Tuesday",
   "Wed" => "Wednesday",
   "Thu" => "Thursday",
   "Fri" => "Friday",
   "Sat" => "Saturday",
   "Sun" => "Sunday");

$month_array = array(1 => "Jan", "Feb", "Mar", "Apr", "May", "Jun",
 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

/*
 * Check our arguments are valid.
 */

/*
 * $day must be either a full day string or the 3 letter
abbreviation.
 */
if (!(in_array($day, $day_array) ||
array_key_exists($day, $day_array))) {
echo "num_days: invalid argument. \$day must be day name or
three letter abbreviation";
return;
}

/*
 * $month must be either a full month name or its 3 letter
abrreviation
 */
if (($mth = array_search(substr($month,0,3), $month_array)) <= 0) {
echo "num_days: invalid argument. \$month must be month name
or three letter abbreviation";
return;
}

/*
 * Now fetch the previous $day of $month+1 in $year;
 * this will give us the last $day of $month.
 */

/*
 * Calculate the timestamp of the 01/$mth+1/$year.
 */
$time = mktime(0,0,0,$mth+1,1,$year);

$str = strtotime("last $day", $time);

/*
 * Return nth day of month.
 */
$date = date("j", $str);

/*
 * If the difference between $date1 and $date2 is 28 then
 * there are 5 occurences of $day in $month/$year, otherwise
 * there are just 4.
 */
if ($date <= 28) {
return 4;
} else {
return 5;
}
}

?>

The other function I have does this:

/*
 * nth_day
 *
 * A function that takes a number and a day and returns the date of
 * nth occurrence of that day in the given month and year.
 *
 * Arguments:
 *  nth - the nth occurence required
 *  day - the day required
 *  month - which month are we talking about
 *  year - which year are we talking about
 *
 * Returns:
 *  date - the date on which the nth day occurs in month and year.
 *  or NULL for errors.
 */

Give me a shout if anyone wants this one.

Cheers, Greg.


> -Original Message-
> From: Phil Dowson [mailto:[EMAIL PROTECTED] 
> Sent: 29 September, 2003 16:22
> To: [EMAIL PROTECTED]
> Subject: [PHP] How many Mondays in a month?
> 
> 
> Hi,
> 
> I have posted a similar question in php.db, but I was 
> wondering if someone could help out with a non-db issue. I am 
> trying to display statistics of visitors to my web site, and 
> what I would like to do is show the average number of 
> visitors that have visited the site in a given month for a 
> certain day e.g..:
> 
> Stats for www.mysite.com for 09/2003
> 
> Monday - 15 average - 65 total
> Tuesday - 16 average - 66 total
> Wednesday - 14 average - 65 total
> Thursday - 13 average - 63 total
> Friday - 15 average - 65 total
> Saturday - 5 average - 25 total
> Sunday - 6 average - 28 total
> 
> I have tried a number of ways to do this, but I cannot work 
> out a way to show the number for example Mondays that will be 
> in a given month, which I need to work out the average. I can 
> work out the total easy enough, just not the average.
> 
> TIA
> 
> Phil Dowson
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] How many Mondays in a month?

2003-09-29 Thread Greg Wiley
No problem, just glad it's found some wider use.

Cheers, Greg. 

> -Original Message-
> From: Phil Dowson [mailto:[EMAIL PROTECTED] 
> Sent: 29 September 2003 17:55
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] How many Mondays in a month?
> 
> Greg,
> 
> That worked brilliantly... I bow down to your sheer 
> excellence!!! Thankyou Thankyou Thankyou
> 
> 
> 
> "Greg Wiley" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> er.demon.net...
> Funny you should ask this because I've been meaning to share 
> some code that I wrote a few months ago that does exactly 
> this for any day of the week.
> 
> Please feel free to use this and make changes. I'd appreciate 
> any changes/bug fixes being sent back to me though.
> 
>  /*
>  * num_days
>  *
>  * A function that takes a day, a month and a year and 
> returns the number of
>  * occurrences of that day in the given month and year.
>  *
>  * Arguments:
>  * day - the day required
>  * month - which month are we talking about
>  * year - which year are we talking about
>  *
>  * Returns:
>  * occ - the number of times the day occurs in the month.
>  * or NULL if there are invalid parameters.
>  */
> function num_days ($day, $month, $year)
> {
> $day_array = array("Mon" => "Monday",
>"Tue" => "Tuesday",
>"Wed" => "Wednesday",
>"Thu" => "Thursday",
>"Fri" => "Friday",
>"Sat" => "Saturday",
>"Sun" => "Sunday");
> 
> $month_array = array(1 => "Jan", "Feb", "Mar", "Apr", "May",
"Jun",
>  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
> 
> /*
> * Check our arguments are valid.
> */
> 
> /*
> * $day must be either a full day string or the 3 letter
abbreviation.
> */
> if (!(in_array($day, $day_array) ||
> array_key_exists($day, $day_array))) { echo "num_days: 
> invalid argument. \$day must be day name or three letter 
> abbreviation"; return; }
> 
> /*
> * $month must be either a full month name or its 3 letter 
> abrreviation */ if (($mth = array_search(substr($month,0,3), 
> $month_array)) <= 0) { echo "num_days: invalid argument. 
> \$month must be month name or three letter abbreviation";
return; }
> 
> /*
> * Now fetch the previous $day of $month+1 in $year;
> * this will give us the last $day of $month.
> */
> 
> /*
> * Calculate the timestamp of the 01/$mth+1/$year.
> */
> $time = mktime(0,0,0,$mth+1,1,$year);
> 
> $str = strtotime("last $day", $time);
> 
> /*
> * Return nth day of month.
> */
> $date = date("j", $str);
> 
> /*
> * If the difference between $date1 and $date2 is 28 then
> * there are 5 occurences of $day in $month/$year, otherwise
> * there are just 4.
> */
> if ($date <= 28) {
> return 4;
> } else {
> return 5;
> }
> }
> 
> ?>
> 
> The other function I have does this:
> 
> /*
>  * nth_day
>  *
>  * A function that takes a number and a day and returns the date
of
>  * nth occurrence of that day in the given month and year.
>  *
>  * Arguments:
>  * nth - the nth occurence required
>  * day - the day required
>  * month - which month are we talking about
>  * year - which year are we talking about
>  *
>  * Returns:
>  * date - the date on which the nth day occurs in month and
year.
>  * or NULL for errors.
>  */
> 
> Give me a shout if anyone wants this one.
> 
> Cheers, Greg.
> 
> 
> > -Original Message-
> > From: Phil Dowson [mailto:[EMAIL PROTECTED]
> > Sent: 29 September, 2003 16:22
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] How many Mondays in a month?
> >
> >
> > Hi,
> >
> > I have posted a similar question in php.db, but I was
wondering if 
> > someone could help out with a non-db issue. I am trying to
display 
> > statistics of visitors to my web site, and what I would 
> like to do is 
> > show the average number of visitors that have visited the site
in a 
> > given month for a certain day e.g..:
> >
> > Stats for www.mysite.com for 09/2003
> >
> > Monday - 15 average - 65 total
> > Tuesday - 16 average - 66 total
> > Wednesday - 14 average - 65 total
> > Thursday - 13 average - 63 total
> > Friday - 15 average - 65 total
> > Saturday - 5 average - 25 total
> > Sunday - 6 average - 28 total
> >
> > I have tried a number of ways to do this, but I cannot work 
> out a way 
> > to show the number for example Mondays that will be in a 
> given month, 
> > which I need to work out the average. I can work out the total
easy 
> > enough, just not the average.
> >
> > TIA
> >
> > Phil Dowson
> >
> > --
> > PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: 
> > http://www.php.net/unsub.php
> >
> >
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] How many Mondays in a month?

2003-09-29 Thread Greg Wiley
> -Original Message-
> From: Burhan Khalid [mailto:[EMAIL PROTECTED] 
> 
> Greg Wiley wrote:
> > Funny you should ask this because I've been meaning to 
> share some code 
> > that I wrote a few months ago that does exactly this for 
> any day of the week.
> > 
> > Please feel free to use this and make changes. I'd appreciate
any 
> > changes/bug fixes being sent back to me though.
> > 
> [ snip ]
> > function num_days ($day, $month, $year) {
> [ snip ]
> 
> One tip that I would add is that instead of using individual 
> arguments, you might want to consider using an array as an 
> argument. This prevents people from inserting the arguments 
> in the wrong order, which would not yield the correct results.
> 
Thanks, that's a good idea; though I would have to change my form
code to match:-(

When I make this change, where would be a good place to submit it?

Cheers, Greg.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] How many Mondays in a month?

2003-09-30 Thread Greg Wiley
> -Original Message-
> From: Cristian Lavaque [mailto:[EMAIL PROTECTED] 
> 
> You could also put the input values in dropdown menus, at 
> least day and month. That way you make sure the input to the 
> funtion is correct everytime.
> 

The code is just a function it's not a "page" in itself. I use it
in a form that display checkboxes for each Sunday in a month.
Someone else may use it by providing the arguments via a form in
the manner you suggest. The function, however, is just that, a
function.

Cheers, Greg.
-- 
Greg Wiley
http://wileysworld.org/ 



Mail was checked for spam by the Freeware Edition of No Spam Today!
The Freeware Edition is free for personal and non-commercial use.
You can remove this notice by purchasing a full license! To order
or to find out more please visit: http://www.no-spam-today.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Form Actions

2003-09-30 Thread Greg Wiley
> -Original Message-
> From: Shaun [mailto:[EMAIL PROTECTED] 
>
> Hi,
> 
> I have a number of forms on my site, and each form can be 
> accessed from a number of different pages. Can anyone suggest 
> a way I can monitor this so that when the submit button is 
> pressed the user is returned to the page they were on before. 
> This is also complicated by the fact that I have a system 
> that returns the user to the same page if there are errors on 
> the form...
> 
I do this by passing a hidden value in the post. The value can
identify anything you like, on mine it identifies the domain the
form was submitted from (though thinking about this now I can do
this without a hidden value, but you get the idea!).

The problem with this is that it means you have to have a separate
copy of each form unless you can construct the hidden input value
using other variables.

Cheers, Greg.
-- 
Greg Wiley
http://wileysworld.org/ 



Mail was checked for spam by the Freeware Edition of No Spam Today!
The Freeware Edition is free for personal and non-commercial use.
You can remove this notice by purchasing a full license! To order
or to find out more please visit: http://www.no-spam-today.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Date Sorting

2003-10-01 Thread Greg Wiley
Apologies if this has been asked before but I couldn't find
anything on google or any of the PHP code sites that quite fits my
requirements. Here's the problem:

I have a form which presents the user with a table of dates with
checkboxes for a three month period, e.g.

Dec 7th 14th21st28th
am  [ ] [ ] [ ] [ ]
pm  [ ] [ ] [ ] [ ]

Jan 4th 11th18th25th
am  [ ] [ ] [ ] [ ]
pm  [ ] [ ] [ ] [ ]

Feb 1st 8th 15th22nd29th
am  [ ] [ ] [ ] [ ] [ ]
pm  [ ] [ ] [ ] [ ] [ ]

When the user submits the form with any of the boxes checked I
want to have these sorted into date order.

If I check Dec 28th am and pm, Jan 4th am and pm, Jan 18th am and
pm and Feb 15th am and pm then the order returned in the _POST is:

Dec 28 am, Dec 28 pm, Jan 4 am, Jan 18 am, Jan 4 pm, Jan 18 pm,
Feb 15 am, Feb 15 pm

This is, I believe, due to the order of the elements in the form.
I tried using tabindex to influence the order returned but to no
avail. So I'm now trying to do this in the php code that processes
the submission. There is no year info such that I could turn the
dates into timestamp and sort that way. Has anyone got any code
that can sort this correctly?

Cheers, Greg.
-- 
Greg Wiley
http://wileysworld.org/ 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date Sorting

2003-10-01 Thread Greg Wiley
> -Original Message-
> From: Jason Wong [mailto:[EMAIL PROTECTED] 
[problem snipped]
> 
> Incorporate whatever sorting info you need into the value of 
> the checkbox.
> 
> name="Dec 28 am" 
>  value="">
> 

Thanks, someone else suggested this and I think this is the method
I shall use.

Cheers, Greg.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Date Sorting

2003-10-01 Thread Greg Wiley
> -Original Message-
> From: Greg Wiley [mailto:[EMAIL PROTECTED] 
> 
> > -Original Message-
> > From: Jason Wong [mailto:[EMAIL PROTECTED]
> [problem snipped]
> > 
> > Incorporate whatever sorting info you need into the value of
the 
> > checkbox.
> > 
> >>  name="Dec 28 am" 
> >  value="">
> > 
> 
> Thanks, someone else suggested this and I think this is the 
> method I shall use.
> 
And this was the method that worked! Thanks for all those who took
the trouble to respond you've helped fixed a problem that's been
bugging me for a couple of days.

Cheers, Greg.
-- 
Greg Wiley
http://wileysworld.org/ 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Find the last friday of each month.

2003-10-26 Thread Greg Wiley
Evan Nemerson wrote:

Search for 'doomsday algorithm' on google. Once you grok it, you should be 
able to figure out the last friday quite easily.

On Sunday 26 October 2003 11:37 am, OrangeHairedBoy wrote:
 

Hi all,

I'm trying to write a script to get the next last friday of the month and I
am failing miserably. It keeps giving me October 10th. So, I scrapped it.
Basically, I just want to show what the last friday of the month is, and if
that date has already passed, show the last friday of the next month.
How can I do that?
   

 

Use strtotime("last Friday");

Cheers, Greg.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php