• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matching strings

In my blog type app I used
$this->db->where('title', $this->uri->rsegment(3));
to match an entry(didn't use traditional "id" here).

1. If a entry in db is like "My post title a" then matching [assume $this->uri->rsegment(3) is "My post title a"] doesn't work. See each word is separated by "space".

2. But ff a entry in db is like "my-post-title a" then matching [assume $this->uri->rsegment(3) is "my-post-title a"] works. To do this I will have to enter title entries into db as "my-post-title a" which I don't want. See each word is separated by "-".

So how do I make 1(space) work?

[eluser]Michael Wales[/eluser]
I usually have a field for the title and when that is submitted I not only save the title to the database but a "slug" as well. The slug is simply the title turned into a URL form (for example "My Post Title" becomes my-post-title).

The easiest way to accomplish this is via the URL Helper's url_title() function.

Then, you can just pass the slug as a parameter of the URL and use it to return your result.

I will be importing contents from .csv files using phpMyAdmin. So I wanted to accomplish something like
$this->db->where(url_title($title), $this->uri->rsegment(3));
. which doesn't work here.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

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