Jump to content


Photo

Howto concatenate <select> values and save in a single variable?


  • Please log in to reply
9 replies to this topic

#1 daniish

daniish
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 08 October 2006 - 07:18 PM

Hello,

I have the following date selector in an html form:

<form name=add_blog action="insert.php" method="post">

Title: <br><input type="text" size="79" id="title" method="post" name="title"></input> <br><br>

Date: <br>
<select id="daydropdown"></select> 
<select id="monthdropdown"></select> 
<select id="yeardropdown"></select> <br><br>

How do i concatenate the DATE values and save them in a variable that i can assign to a field in my SQL database?


Many thanks for your help

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 October 2006 - 08:32 PM

Use this as the html for your drop down menus
<select id="dropdown['day']"></select> 
<select id="dropdown['month']"></select> 
<select id="dropdown['year']"></select>

Then you can access the day, month and year in a single variable called ($_POSt['dropdown'], which will hold an array of the three drop downs.
To access the day you can use $_POST['dropdown']['day'], for the the month you use $_POST['dropdown']['month'] and $_POST['dropdown'][year'] to get the year.

When you want to add them into the database, you can use implode function. Eg:
$date = implode("-", $_POST['dropdown'];

What this will do is produce something like this: day-month-year

Does that help?




#3 daniish

daniish
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 08 October 2006 - 09:15 PM

Hmm i like arrays:)

do you think i can get your method to work with the javascript i am using:
http://www.javascrip...dateform2.shtml

Cheers!

#4 daniish

daniish
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 08 October 2006 - 09:35 PM

SOLVED!

Many thanks for your help  ;D

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 10 October 2006 - 03:40 PM

Of course, you could just use a proper date picker and be done with it.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 19 October 2006 - 06:29 AM

Hey fenway,

what do you mean with a date picker ?
do you have a url with some more explanation ?

kind regards
anatak
takasi.8008@docomo.ne.jp
tourokum@0508.jp

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 04:43 PM

A custom control that a) makes sure you pick a valid date and b) places the full SQL-99 date string into a form field.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#8 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 19 October 2006 - 09:48 PM

ah ok.
I see. I thought you knew some mysterious function that did all the above for you.
custom = self written

thx
anatak
takasi.8008@docomo.ne.jp
tourokum@0508.jp

#9 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 19 October 2006 - 10:13 PM

That's generally the only way to get anything done properly ;-)
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#10 anatak

anatak
  • Members
  • PipPipPip
  • Advanced Member
  • 406 posts
  • LocationJapan, Fukuoka prefecture, Kitakyushu City

Posted 23 October 2006 - 05:38 AM

true
and since I have a real dislike for programming anything time related I was more than interested to get my pawns on a killer function that does it for me ;)

takasi.8008@docomo.ne.jp
tourokum@0508.jp




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users