CodeIgniter Forums
Matching strings - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Matching strings (/showthread.php?tid=7524)



Matching strings - El Forum - 04-13-2008

[eluser]Animas[/eluser]
In my blog type app I used
Code:
$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?


Matching strings - El Forum - 04-13-2008

[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.


Matching strings - El Forum - 04-13-2008

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