Jump to content

Recommended Posts

Hi,

I have a mysql table with following fields
id – int
company – varchar(50)
cost – decimal(5,2)

Updated - datetime

 

Example of data:
101 company1 120.10 2013-05-22 10:21:19
102 company2 121.20 2013-05-22 11:11:29
103 company3 120.15 2013-05-23 12:44:10
104 company4 124.25 2013-05-23 13:26:49

 

Following is the text field code for cost:

Cost: <input type="text" name="txtcost"><br />

How will my php code be if I want to insert Pound and Pence from two form field to one mysql field like this or if there is better method please advice.

<select name="pound">
  <option value="0" selected="selected">Pound:</option>
  <option value="120">120</option>
  <option value="121">121</option>
  <option value="122">122</option>
  <option value="123">123</option>
  <option value="124">124</option>
  <option value="125">125</option>
</select>
<select name="pence">
  <option value="0" selected="selected">Pence:</option>
  <option value="00">00</option>
  <option value="10">10</option>
  <option value="15">15</option>
  <option value="20">20</option>
  <option value="25">25</option>
  <option value="30">30</option>
</select>

Your help will be much appreciated, thank you.

Honestly, it's probably easier for the users if you just let them type in the value. In American we use dollars and cents, but rather than having one drop down for dollars and another for cents, almost anywhere you'd need to enter in a monetary value, you'd simply enter: $dd.dd in a text field. (where d=digit).

It gets a little more complicated to parse it when you get to larger values where people add the thousands separator, but there are PHP functions to help with that (and you should have your locale settings set to the right one.)

Your field won't allow anything over 999.99 so you're fine.

Edited by Jessica
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.