Hi guys!
I need to make a dropdown list using CAutoComplete. Everything is set and works fine, here is my code of the action:
<?php
public function actionSuggestCharacter() {
if(Yii::app()->request->isAjaxRequest && isset($_GET['q'])) {
$name = $_GET['q'];
$criteria = new CDbCriteria;
$criteria->condition='`Character` LIKE :keyword';
$criteria->params=array(':keyword'=>"$name%");
$criteria->limit = 5;
$suggestions = zCharacter::model()->findAll($criteria);
$returnVal = '';
foreach($suggestions as $suggestion) {
$returnVal .= $suggestion->Character."\n";
}
if (isset($suggestion)) {
echo $returnVal;
}
$criteria->condition='`Character` LIKE :keyword';
$criteria->params=array(':keyword'=>"%$name%");
$criteria->limit = 5;
$suggestions = zCharacter::model()->findAll($criteria);
$returnVal = '';
foreach($suggestions as $suggestion) {
$returnVal .= $suggestion->Character."\n";
}
if (isset($suggestion)) {
echo $returnVal;
}
}
}
?>
What this code does is that it shows the first 5 matches with the keyword at the beginning and the next 5 matches are with the keyword in any place.
Example. Let's say a user types in the input field "pdd" (doesn't really matter, could be any text), so the results returned by autocomplete will look like:
1. pddtext...
2. pddtext...
3. pdd_some_other_text
4. pdd_text
5. pdd_text
1. text_text_pdd
2. text_pdd_text
3. etc...
The problem is I need to separate these two blocks by some kind of line (<hr>
or <div>
with the border). How can I do this?
Thank you.