![]() |
unique url (slug) and check - 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: unique url (slug) and check (/showthread.php?tid=16421) |
unique url (slug) and check - El Forum - 03-06-2009 [eluser]freshface[/eluser] Hey I am creating a slug for my url title but i want to check if it is unque in my database. when i have: ci-rocks and i post another title with ci-rocks it should become ci-rocks-1 but if i post another time ci-rocks it should become ci-rocks-2 and so on. But i have a proplem with my recusion in my model. Code: var $counter = 0; Does somebody know my mistake? unique url (slug) and check - El Forum - 03-06-2009 [eluser]xwero[/eluser] Why make it so difficult? Code: function unique_slug($slug) unique url (slug) and check - El Forum - 03-06-2009 [eluser]freshface[/eluser] Thx, i was playing around with your code and it seems that it always returns the slug + postfix. When 'ci-rocks' is unique it creates 'ci-rocks-1' The first if statement always seems to be true because $query->num_rows is always 1 even when there are no records in the db. Am i correct? Regards. unique url (slug) and check - El Forum - 03-06-2009 [eluser]xwero[/eluser] You are right, the solution is Code: $prev_max = $this->db->select_max('slug')->like('slug',$slug,'after')->get('blog_blog')->row()->slug; unique url (slug) and check - El Forum - 03-06-2009 [eluser]freshface[/eluser] Works great, thx. |