• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Show highlight match in list

#1
I have this function below where if I type in my input it displays a list of categories 

But on the list I below input I need the letter highlighted if possible 

For example if I type in letter a in input it should be show bold in list.

Is that possible to do so? How would I do so? Thanks for your time

[Image: tags_zpswj8pkdxr.png]

Controller


PHP Code:
<?php

class Welcome extends CI_Controller {

public function 
tags() {

$data['tags'] = array();

if (
$this->input->post('tag_name') !== "") {

$this->db->like('tag_name'$this->input->post('tag_name'), 'after');
$results $this->db->get('tag');

foreach (
$results->result_array() as $result) {
$data['tags'][] = array(
'tag_id' => $result['tag_id'],
'tag_name' => $result['tag_name']
);
}
}

echo 
json_encode($this->load->view('tags'$dataTRUE));
}


Tag View


PHP Code:
<?php if ($tags) {?>
<div class="tag_list_inner">
<?php foreach (array_chunk($tags4) as $tag) { ?>
<div class="row">
<?php foreach ($tag as $tag) {?>
<div class="col-sm-3 col-xs-6 text-center">
<a><?php echo $tag['tag_name'];?></a>
</div>
<?php }?>
</div>
<?php }?>
</div>
<?php }?>

Script

Code:
<script type="text/javascript">
$("#tag_name").on('keyup', function(e){
    $.ajax({
        url: '<?php echo base_url('welcome/tags');?>',
        type: "post",
        data: {
            tag_name: $('#tag_name').val()
        },
        dataType: "json",
        success: function(json){
            $('#tag_list').html(json);
        }
    });
});        
</script>


Attached Files
.php   welcome_message.php (Size: 1.32 KB / Downloads: 53)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply

#2
Found what I am after text helper 

Codeigniter has a lot of great things

highlight_phrase($result['tag_name'], $this->input->post('tag_name'), '<span style="color:#990000;">', '</span>')


PHP Code:
public function tags() {

$this->load->helper('text');

$data['tags'] = array();

if (
$this->input->post('tag_name') !== "") {

$this->db->like('tag_name'$this->input->post('tag_name'), 'match');
$results $this->db->get('tag');

foreach (
$results->result_array() as $result) {
$data['tags'][] = array(
'tag_id' => $result['tag_id'],
'tag_name' => highlight_phrase($result['tag_name'], $this->input->post('tag_name'), '<span style="color:#990000;">''</span>')
);
}
}

echo 
json_encode($this->load->view('tags'$dataTRUE));

[Image: tag2_zpsl7olob3w.png]
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.