Load Posts With First Letter

Hello

How I can return posts with first letter of title, In Sql we can use below code:

SELECT *

FROM posts

WHERE title LIKE ‘%B’

LIMIT 0 , 30

How in Yii ?!

Assume you already have Posts model,

then it should be Posts::model->findAll(“title LIKE ‘B%’”);

Or if you like, you can use dbcommand. See link:

http://www.yiiframework.com/doc/guide/1.1/en/database.dao

$posts = Yii::app()->db->createCommand()

->from('posts')


->where("title LIKE 'B%'")


->queryAll();

Thank you my friend, It’s Good.

[font="Tahoma"]

For standard characters it’s OK, How I can request posts with Persian characters (UTF8), This code not work:

Posts::model->findAll(“title LIKE ‘ب%’”);

  • ب is B in persian alphabet. *

[/font]

Try this:


Posts::model->findAll("title LIKE :q", array(':q' => 'ب%'));

PS. wow, you have built-in emoticons in your alphabet. How cool is that?

Thank you, It’s Worked.

Yes ! In some alphabets we can use characters as a emoticons !

You can see HERE about Persian standard alphabet .

Yeah, arabic script is beautiful, looks like ornament or something.

I should definitely learn it.

Persian language is beautiful too, It’s Very nice language.

Content AND design in one entity.

Amazing.