Forum Moderators: coopster

Message Too Old, No Replies

swap place of form values

         

helenp

10:12 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,
I have an form where I put together the month and year, because it is better that way, the day I have separately.
Like this:
<select name="month" size="1">
<option value="2006-01">January 2006</option></select>
<select name="day" size="1">
<option>01</option></select>

In the phpcode I put the dates together like this:
$arrival = $month."-".$day;

But the problem is when I print the arrival day out, I get year-month-day, and I would like to print out day-month-year.

Is it possible to do that without separating the month and year?

Birdman

11:06 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need to split the month/year up into separate form elements, you can just explode the form value on the hyphen.

$monthyear = explode('-', $arrival);
$arrival = $day .'-'. $monthyear[1] .'-'. $monthyear[0];

simon2263

11:10 am on Jan 22, 2006 (gmt 0)

10+ Year Member



Wouldn't it be easier to swap the month and year values in the value of the option tag so they look like this:

<option value="01-2006">January 2006</option>

Then in the php code, write:

$arrival = $day."-".$month;

Simon

helenp

11:19 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Birdman:I just tried it but only print out the day value and 2 --
Something is wrong.

$month = explode('-', $arrival);
$arrival = $day .'-'. $month[1] .'-'. $month[0];

Simon: No I canīt do that, I need the values for mysql.

helenp

11:30 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Uups,
works now thanks,
Didnīt know that
$arrival = $month."-".$day;
had to be as well :)

helenp

11:39 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



uups again,
It does print out the dates as I want now,
but the database search donīt work as I use the same var $arrival....

helenp

11:54 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi again,
Stupid me,
I fixed just to put the explode in the while and works like a charm, thanks again.

Birdman

11:59 am on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello again,

You could just create a new var for displaying the date and keep the original $arrival for your search.

$arrival = $month."-".$day;

$monthyear = explode('-', $arrival);
$arrival_display = $day .'-'. $monthyear[1] .'-'. $monthyear[0];

Now just edit the script where you display the date, changing it to $arrival_display.

Hope it helps.

Edit: Glad you got it fixed

helenp

12:04 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, that is a better way, if you need the var more times you donīt have to put the code in all { }
thanks