Save select box value not ID

2010-05-18 Thread csj16

I have 2 tables and models 'Friend' and 'Message'. I have a belongsTo
association between them, and this is all working fine.

The select box in my form is being populated with the correct field, that's
perfect, BUT when the form is submitted it saves the ID of that field not
the name. Which is obvious as its a INTEGAR field.

But I would like to find out if it's at all possible to ALSO save the name
that shows in the drop down-list. So let's say the drop-down list is
populated with different types of fruits (apples, oranges, cherries and
peaches) but when the form is submitted/saved it doesn't save the name of
the fruit it saves the ID of that field. Is there anyway to also save the
name of the fruit into the database?

I am new to CakePHP so I am utterly clueless, but would really appreciate
some help.
-- 
View this message in context: 
http://old.nabble.com/Save-select-box-value-not-ID-tp28599700p28599700.html
Sent from the CakePHP mailing list archive at Nabble.com.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Save select box value not ID

2010-05-18 Thread euromark
usually you would retrieve the name of the fruit later on by just de-
referencing (table joins) its id
this way you prevent data redundancy

if redundancy is wanted you might want to retrieve the value before
actually saving this-data
or you can remove the integers prior to displaying the dropdown form -
replacing them with the values as well:

value1 = value1
value2 = value2

depending on the specific scenario



On 18 Mai, 21:22, csj16 chic...@gmail.com wrote:
 I have 2 tables and models 'Friend' and 'Message'. I have a belongsTo
 association between them, and this is all working fine.

 The select box in my form is being populated with the correct field, that's
 perfect, BUT when the form is submitted it saves the ID of that field not
 the name. Which is obvious as its a INTEGAR field.

 But I would like to find out if it's at all possible to ALSO save the name
 that shows in the drop down-list. So let's say the drop-down list is
 populated with different types of fruits (apples, oranges, cherries and
 peaches) but when the form is submitted/saved it doesn't save the name of
 the fruit it saves the ID of that field. Is there anyway to also save the
 name of the fruit into the database?

 I am new to CakePHP so I am utterly clueless, but would really appreciate
 some help.
 --
 View this message in 
 context:http://old.nabble.com/Save-select-box-value-not-ID-tp28599700p2859970...
 Sent from the CakePHP mailing list archive at Nabble.com.

 Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
 their CakePHP related questions.

 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com For more options, visit this group 
 athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Save select box value not ID

2010-05-18 Thread Jeremy Burns
You say you are new to Cake - have you done any web or database development at 
all? A select box is usually populated from a table that is joined or 
associated with the table you are updating. You only need to store the id of 
the related row in 'this' table. To find out what value that id relates to, you 
do a query with a join. This is standard referential integrity stuff and not 
just Cake specific.

So if you had a table that contained trees and you wanted to know what fruit 
each tree grows, you'd have a 'trees' table with these fields called 'id, 
'name', 'fruit_id'. Then you'd have a table called 'fruits' with fields called 
'id' and 'name' (this is the Cake convention - and it is worth sticking to it). 
If your fruits table looks like this:

id : name
1 : Apples
2 : Oranges
3 : Cherries
4 : Peaches

...and you have a row in your trees table like this:
id : name : fruit_id
1 : My cherry tree : 3

...you look up the fruit_id (3) in your fruits table, and you can see that 3 = 
Cherries. Therefore the tree with the id of 1 grows cherries.

This gives you enormous flexibility in the future. I know it's highly unlikely 
that you'd ever want to do this with fruits and trees, but let's say your tree 
suddenly starts growing oranges instead of cherries. All you do update the row 
of the trees table where the id is 1, changing the value in the fruit_id field 
from 3 to 2. Now when you do the same look up you see that the tree grows 
oranges.

Perhaps a better example is if you wanted to be more precise, and instead of 
recording your fruit as 'Cherries' you want to record it as 'Red cherries'. All 
you do is update the 'name' field in the 'fruits' table from 'Cherries' to 'Red 
cherries'. Now when you do your query all trees that used to grow cherries now 
grow red cherries. That's a single update. If you were to do what you want to 
do and store the name of the fruit in the trees table, you'd have to update 
multiple rows in the trees table instead. That sounds simple enough, but 
imagine if you had to do that for your entire orchard - that's a lot of 
updates. And then you have the potential problems caused by a random user 
changing a couple of trees from 'Cherries' to 'Cheeries' by mistake.

If you are new to Cake and these concepts, I'd recommend you read the following 
parts of the online guide. In particular, look at the section on Baking. This 
is invaluable stuff. Al you do is build your database, point Cake at it and it 
will build a simple app for you. Then you can look at the code and see how it 
all works, and go on from there.

http://book.cakephp.org/view/1000/Models
http://book.cakephp.org/view/1522/Code-Generation-with-Bake

Jeremy Burns
jeremybu...@me.com


On 18 May 2010, at 20:22, csj16 wrote:

 
 I have 2 tables and models 'Friend' and 'Message'. I have a belongsTo
 association between them, and this is all working fine.
 
 The select box in my form is being populated with the correct field, that's
 perfect, BUT when the form is submitted it saves the ID of that field not
 the name. Which is obvious as its a INTEGAR field.
 
 But I would like to find out if it's at all possible to ALSO save the name
 that shows in the drop down-list. So let's say the drop-down list is
 populated with different types of fruits (apples, oranges, cherries and
 peaches) but when the form is submitted/saved it doesn't save the name of
 the fruit it saves the ID of that field. Is there anyway to also save the
 name of the fruit into the database?
 
 I am new to CakePHP so I am utterly clueless, but would really appreciate
 some help.
 -- 
 View this message in context: 
 http://old.nabble.com/Save-select-box-value-not-ID-tp28599700p28599700.html
 Sent from the CakePHP mailing list archive at Nabble.com.
 
 Check out the new CakePHP Questions site http://cakeqs.org and help others 
 with their CakePHP related questions.
 
 You received this message because you are subscribed to the Google Groups 
 CakePHP group.
 To post to this group, send email to cake-php@googlegroups.com
 To unsubscribe from this group, send email to
 cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
 http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: save select

2007-06-28 Thread [EMAIL PROTECTED]

I could be wrong, but I think there's only two ways to solve this.

1. Have a select with possibility to select multiple values, and
onsubmit have a javascript function that loops through all the
options of it and makes them selected.

2. On submit, have a javascript loop through the options and assign
the values to a hidden element. Won't demand you to use a multiple-
select.

Both of these demand javascript, so maybe a better way would be to
assign the values to a hidden field while creating the select on the
server. Then again, I guess you use javascript on the page anyway...?

cheers / Wille

On Jun 25, 10:48 pm, Oscar Burgos [EMAIL PROTECTED] wrote:
 I have declare two selectTag in my form and I need to save all valuesg, but
 from the second select not just selected.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



save select

2007-06-25 Thread Oscar Burgos

hi all bakers...I need a little help

I have declare two selectTag in my form and I need to save all values
from the second select not just selected.

any sugestions?? thank you


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---