Welcome Guest, Not a member yet? Register   Sign In
Matching strings
#1

[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?
#2

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

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




Theme © iAndrew 2016 - Forum software by © MyBB