Yii Framework Forum: dropDownList > dropDownList > findAll > order - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

dropDownList > dropDownList > findAll > order Rate Topic: -----

#1 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 20 March 2012 - 12:13 PM

Ok here goes

I cant seem to get this sort order working, but from everything i've read, it should be working! ???

The database has a table with form field contents in, so for example to select age in a drop down, it finds all the rows with an id_field value of 2, and puts them in the drop down, great.

id id_field value
1 2 18
2 2 19
3 2 20
4 2 21
...


This is the dropdown code

<?php echo $form->dropDownList($model,'client_2_age', CHtml::dropDownList(FormFields::model()->findAll("id_field=2",array('order' => 'value ASC')), 'value', 'value'), array('empty'=>'Select age')) ?>


I thought it was working, until someone 'kindly' pointed out i hadnt included the age "58" so i added it to to DB, and sure enough it appeared in the dropdown, but as the last entry. :-X

I cant get it to position itself between 57 and 59! >:(

I obviously entered them into the DB in the correct order, so thought it was working, doh! :o

Any help appreciated.

ps sorry about the icons, they are keeping me 'up beat' lol
0

#2 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 12 April 2012 - 07:08 AM

anyone?

It seems strange that its not sorting... it's showing Value ok, but not sorting by Value

<?php echo $form->dropDownList($model,'client_1_age', CHtml::listData(FormFields::model()->findAll("id_field=2",array('order' => 'value ASC')), 'value', 'value'), array('empty'=>'Select age')) ?>


:(
0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 12 April 2012 - 07:43 AM

I think it should be
<?php echo $form->dropDownList($model,'client_1_age', CHtml::listData(FormFields::model()->findAll(array('condition'=>'id_field=2', 'order' => 'value ASC')), 'value', 'value'), array('empty'=>'Select age')) ?>


Does it help?

PS But of course you can write, if no order needed:
<?php echo $form->dropDownList($model,'client_1_age', CHtml::listData(FormFields::model()->findAll('id_field=2'), 'value', 'value'), array('empty'=>'Select age')) ?>

1

#4 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 12 April 2012 - 11:19 AM

View Postbennouna, on 12 April 2012 - 07:43 AM, said:

I think it should be
<?php echo $form->dropDownList($model,'client_1_age', CHtml::listData(FormFields::model()->findAll(array('condition'=>'id_field=2', 'order' => 'value ASC')), 'value', 'value'), array('empty'=>'Select age')) ?>


Does it help?



YES!!!! that works, thank you, i didnt know about this condition part, i will now go and fix alot of dropdowns..

One thing thats not 100% perfect, is that in a list of 18 to 100.. 100 is at the top (I know that logically 10x is higher than 18)

How can I solve that? perhaps i change it to 18 to 99 lol
1

#5 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 12 April 2012 - 12:18 PM

Quote

One thing thats not 100% perfect, is that in a list of 18 to 100.. 100 is at the top (I know that logically 10x is higher than 18)

How can I solve that? perhaps i change it to 18 to 99 lol


Glad it worked. Now, are you sure your data field is of some numeric type? It looks like it's a string type to behave like that.
0

#6 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 13 April 2012 - 08:24 AM

Do you mean in the database? it's set to a Varchar because it holds data from any type of form element, for example MR, MRS, MISS etc.

not sure how to set a data type in Yii yet.. I will research

View Postbennouna, on 12 April 2012 - 12:18 PM, said:

Glad it worked. Now, are you sure your data field is of some numeric type? It looks like it's a string type to behave like that.

0

#7 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 13 April 2012 - 09:21 AM

Yes, in the db. I'm talking about your 'value' column. It should be numeric (TINYINT unsigned is enough for ages if you use MySQL).

Now, do you mean you store ages AND titles/civilities in the same column?
0

#8 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 16 April 2012 - 04:33 AM

uhm, yes *hides behind pillow* dont hurt me!

I just wanted to store all the "pre poulated" field values somewhere, so that I can change them once, and all forms get updated - also at some point, allow Admin to set them via the GUi...

MySQL yep. Perhaps then I should create two columns, one varchar, the other int..

View Postbennouna, on 13 April 2012 - 09:21 AM, said:

Yes, in the db. I'm talking about your 'value' column. It should be numeric (TINYINT unsigned is enough for ages if you use MySQL).

Now, do you mean you store ages AND titles/civilities in the same column?

0

#9 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,168
  • Joined: 05-January 12
  • Location:Morocco

Posted 16 April 2012 - 05:01 AM

View PostThePaulius, on 16 April 2012 - 04:33 AM, said:

uhm, yes *hides behind pillow* dont hurt me!


I'm not an angel but I generally don't hurt anyone. I was just surprised :)

I understand what you want to do, but you've already experienced one downside of it for sorting.

And if I were you, UX-wise, I wouldn't really use a dropdown for something like age. I'd rather use a slider. And do you really need to have age values stored in database?

Anyway, I'm really just saying out loud what I think. Feel free to do as you need.

PS I've just realized we are in the Yii 1.0.x subforum… Is it on purpose?
0

#10 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 16 April 2012 - 05:13 AM

Hi,

I've created two columns now, value_int and value_char this has solved the ordering problem. thanks for steering me there.

I'd quite like to use a slider - but for now, im building a quick and dirty application to solve a problem - but that can be built upon going forwards - with things like sliders! actually, i did have a slider ;D for £House Value, but ran into difficulties, so bailed until I have time to go back and make it work..

Oh, didnt realise i was in the Yii 1.0.x forum, opps.

p

View Postbennouna, on 16 April 2012 - 05:01 AM, said:

I'm not an angel but I generally don't hurt anyone. I was just surprised :)

I understand what you want to do, but you've already experienced one downside of it for sorting.

And if I were you, UX-wise, I wouldn't really use a dropdown for something like age. I'd rather use a slider. And do you really need to have age values stored in database?

Anyway, I'm really just saying out loud what I think. Feel free to do as you need.

PS I've just realized we are in the Yii 1.0.x subforum… Is it on purpose?

0

#11 User is offline   charles07 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 05-February 12

Posted 28 April 2012 - 07:09 AM

thanks bennouna

i was looking to order the dropdownlist by username ASC. Your code really helped me.

<?php echo $form->dropDownList($model,'client_1_age', CHtml::listData(FormFields::model()->findAll(array('condition'=>'id_field=2', 'order' => 'value ASC')), 'value', 'value'), array('empty'=>'Select age')) ?>

0

#12 User is offline   ThePaulius 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 17-February 12

Posted 03 May 2012 - 11:02 AM

Bennouna is a great guy isnt he - even if he is now hiding behind a logo! :lol:

View Postcharles07, on 28 April 2012 - 07:09 AM, said:

thanks bennouna

i was looking to order the dropdownlist by username ASC. Your code really helped me.


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users