user6891871
user6891871

Reputation: 174

str_replace and Replace is not working

I Want to execute this query but it doesn't print anything because of str_replace,I also used Replace in place of str_replace but it doesn't work for me.Where

$name = iFLY-San-Diego-Kids-Club

In database-- its like iFLY San Diego Kids Club

please help anyone to get this. Any help will be appreciated.

Thanks in advance

   $rs = $this->db->select('*')                                                                                                           
          ->from('table')
          ->where('table.status', 'Active')
          ->where('table.id', $id)
          ->where('table.title', str_replace('-',' ',$name))
          ->get()->result();
}

Upvotes: 1

Views: 231

Answers (3)

Alex Mac
Alex Mac

Reputation: 2993

Your query is perfect but instead of where you can use like clause like mentioned below.

->where('table.title', str_replace('-',' ',$name))

Replace with

->like('table.title', str_replace('-',' ',$name))

If you use like then it will automatically add wildcard(%) in your query.

Let me know if it not works.

Upvotes: 5

Anand Pandey
Anand Pandey

Reputation: 2025

You can do this like

$newname = str_replace("-","",$name); 

$rs = $this->db->select('*')                                                                                                           
          ->from('table')
          ->where('table.status', 'Active')
          ->where('table.id', $id)
          ->where('table.title', $newname)
          ->get()->result();
}

Upvotes: 1

Rajeev Radhakrishnan
Rajeev Radhakrishnan

Reputation: 1004

Instead of using str_replace('-',' ',$name) try str_replace('-','_',$name)

Upvotes: 0

Related Questions