Welcome Guest, Not a member yet? Register   Sign In
How do I use the category name rather than the category id in my url?
#1

[eluser]bigmike7801[/eluser]
I am using the CodeIgniter framework and am having trouble figuring out how to get my urls to display the category name but still have my queries reference the category id.

I have a controller set up called jobs. The structure of the url is "example.com/jobs/listings/category_id" example: "example.com/jobs/listings/3" where 3 would be the category id for "software".

I'd rather the url say "example.com/jobs/listings/category_name" example: "example.com/jobs/listings/software".

The problem I'm running into is that the "jobs" table holds stores the category_id that the job belongs to and not the category_name. I have a separate table that holds just the category id's and their names. I'm not sure how to A.) Write my query and B.) Make an SEO friendly url structure.

My current query looks something like "SELECT * FROM jobs WHERE cat_id = 3;

Also, I'm not sure if I should be using mod_rewrite in an .htaccess file or if I should be using the routes.php file in CodeIgniter.

Any help would be greatly appreciated!

-Thanks
#2

[eluser]osci[/eluser]
Your query could be something like this in AR
Code:
$this->db->from('jobs.*, cat_table.description')->join('cat_table','cat_table.id = jobs.cat_id','left')->where('cat_table.description',$url_description)

You of course have to sanitize the url description segment.




Theme © iAndrew 2016 - Forum software by © MyBB