repeater09
(Repeater09)
January 11, 2012, 3:39am
1
Hello i have a dropdownlist that is suppose to ask the user yes or no and they choose and when it saves into the database it only says 0 (yes) or 1(no)…how would i display yes or no?..
here is the snippet from the code:
<?php echo $form->DropDownList($model,‘contactFirst’,array(yes,no)); ?>
Angela88
(Angela Arrie)
January 11, 2012, 4:09am
2
repeater09:
Hello i have a dropdownlist that is suppose to ask the user yes or no and they choose and when it saves into the database it only says 0 (yes) or 1(no)…how would i display yes or no?..
here is the snippet from the code:
<?php echo $form->DropDownList($model,‘contactFirst’,array(yes,no)); ?>
try this
<?php echo $form->DropDownList($model,'contactFirst',array('0'=>'yes','1'=>'no')); ?>
repeater09
(Repeater09)
January 12, 2012, 1:36am
3
nope didn’t work did the same thing…thanks though
macinville
(Macinville)
January 12, 2012, 3:49am
4
Hi repeater09,
I copied your code and used it as is, and it actually works fine. This is the generated HTML when I used it:
<select id="LoginForm_contactFirst" name="LoginForm[contactFirst]">
<option value="0">yes</option>
<option value="1">no</option>
</select>
Can you paste here the HTML generated in your browser? Have you tried other browsers?
ismail
(Mdismail N001)
January 12, 2012, 4:07am
5
take a look at here http://www.yiiframew …alidation-rules .
macinville
(Macinville)
January 12, 2012, 5:06am
6
I think the original problem is about displaying a dropdownlist with yes or no as the options. What’s with the safe validation rules?
ismail
(Mdismail N001)
January 12, 2012, 5:23am
7
oh my bad ,actually it was mistaken by me.
jayanthan
(Jayanthan Webmaker)
January 12, 2012, 5:43am
8
a tricky way just try for fun
<?php echo $form->DropDownList($model,'contactFirst',array('yes'=>'yes','no'=>'no')); ?>
macinville
(Macinville)
January 12, 2012, 5:54am
9
That’s okay. Probably you want to answer to a different concern and mistakenly posted your answer here.
jayanthan
(Jayanthan Webmaker)
January 12, 2012, 6:31am
10
could you please help me in this problem my problem link
ismail
(Mdismail N001)
January 13, 2012, 10:21pm
11
hey did you solve your prob?
repeater09
(Repeater09)
January 14, 2012, 3:30am
12
nothing has worked…I have it showing on the drop down list but when i attempt to look at it on the database or the view page it only shows a 1 or 0…thanks for the help guys i guess its impossible…
Angela88
(Angela Arrie)
January 16, 2012, 2:21am
13
if i’m not wrong, your problem is how to display yes or no in your view page after you save in database and not to save in the database, right??
i don’t know it’s better way to use in yii or not but i do this in my project…
in my sql, i use this
select CASE contactfirst WHEN "0" THEN "Yes" WHEN "1" THEN "No" end as contactfirst ...... from ...... where .....
2.i had function in my model to change that.
public function getContact($val){
if($val==0)
return "Yes";
else if($val==1)
return "No";
}
and call in your view(gridview) with this.
MyModel::model()->getContact($data->contactfirst)
sorry if i misinterpret what you mean because of my bad english…
just want to help
macinville
(Macinville)
January 16, 2012, 5:06am
14
repeater09:
Hello i have a dropdownlist that is suppose to ask the user yes or no and they choose and when it saves into the database it only says 0 (yes) or 1(no)…how would i display yes or no?..
here is the snippet from the code:
<?php echo $form->DropDownList($model,‘contactFirst’,array(yes,no)); ?>
Hi repeater,
I see. I misinterpreted your question. You are talking about "displaying" the values "yes" and "no", so I thought it has something to do with the view. So what you really want is to "save" the values "yes" or "no" to the database, right?
It is not impossible. And in your view, use
<?php echo $form->DropDownList($model,'contactFirst',array('yes'=>'yes','no'=>'no')); ?>
just like jayanthan.ece said. If it is still saving 0 and 1, check the column properties of the table, maybe it is set to int or something. It has to be varchar(3).