Yii Framework Forum: Load text from DB before <!-- more --> tag - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Load text from DB before <!-- more --> tag Rate Topic: -----

#1 User is offline   r.vas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 22-December 09

Posted 14 March 2010 - 07:53 AM

I have

Quote

om mani padme hum
<!-- more -->
om mani bhagavate
in mysql db.

How can i get data before <!-- more --> tag on the mysql side without using php's regexp?
Dev: Win+Wamp (php_5.3.0, mysql_5.1.36, apache_2.2.11)
Prod: Debian (php_5.3.1, mysql_5.1.41, nginx)
---and i'm a total noob
0

#2 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 14 March 2010 - 11:02 AM

SELECT SUBSTRING_INDEX(foo, '<!--more-->',1) AS bar


where 'foo' is the column you want to select.

See substring_index.
0

#3 User is offline   r.vas 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 22-December 09

Posted 21 March 2010 - 02:42 PM

Code from yii blog example (probably partly modified)

    /**
     * Lists all posts.
     */
    public function actionList()
    {
	$criteria = new CDbCriteria;
	$criteria->condition = 'status=' . Post::STATUS_PUBLISHED;

//TODO SELECT SUBSTRING_INDEX till <!-- more --> <<<< here

	$criteria->order = 'createTime DESC';
	$postCount = Post::model()->count($criteria);
	$pages = new CPagination($postCount);
	$pages->pageSize = Yii::app()->params['postsPerPage'];
	$pages->applyLimit($criteria);

	//TODO add tags criteria

	$posts = Post::model()->findAll($criteria);
	$this->render('list', array(
			    'posts'=>$posts,
			    'pages'=>$pages,
	));
    }


And how can i
SELECT SUBSTRING_INDEX(foo, '<!--more-->',1) AS bar
with yii AR in this action?

If <!-- more --> tag is absent full content should be loaded.
Dev: Win+Wamp (php_5.3.0, mysql_5.1.36, apache_2.2.11)
Prod: Debian (php_5.3.1, mysql_5.1.41, nginx)
---and i'm a total noob
0

#4 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 22 March 2010 - 06:15 AM

CDbCriteria has a 'select' attribute.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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