![]() |
Pagination - 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: Pagination (/showthread.php?tid=16250) |
Pagination - El Forum - 03-01-2009 [eluser]Fero[/eluser] but then, when I get to www.fotoramik.sk/blog/kategoria/clanky I get following error: Code: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1,3' at line 1 which means that I should hardcode /1 variable as the last segment, right? Pagination - El Forum - 03-01-2009 [eluser]TheFuzzy0ne[/eluser] Not necessarily. Just ensure that if the last segment is not set, that the default for the variable you pass to the model is 1. Code: $start_result = $this->uri->segment(3); Something like that should do it, and prevent your app from breaking if the URI doesn't contain a page number in it (if it's been tampered with by the user). Pagination - El Forum - 03-01-2009 [eluser]Fero[/eluser] Hmm I still have some weird results, as the test article doesn't show even after this + when I click the 2, the thirt article shows ONLY and I can't comeback to number 1 as if the pagination lib. was broken or something.. And, is this OK? (limit) Code: $data['query']=$this->db->query("SELECT id,odkaz,title,picture,text,date FROM articles WHERE kategoria='".$page."' ORDER BY id DESC LIMIT ".$start_result.",3"); Pagination - El Forum - 03-01-2009 [eluser]TheFuzzy0ne[/eluser] OK, please repost your controller method and your model method. Pagination - El Forum - 03-01-2009 [eluser]Fero[/eluser] Controller (blog.php): Code: function kategoria() Model article.php: Code: function body($page,$category) //page-WHERE klauzula ; kategoria - category pointer Pagination - El Forum - 03-01-2009 [eluser]TheFuzzy0ne[/eluser] I'm quite confused by your code. Please give me a little while to study it and figure out what's what. Pagination - El Forum - 03-01-2009 [eluser]TheFuzzy0ne[/eluser] Sorry, but I am still totally confused by your code. There is a lot you can do to make things more simple for yourself. I'm going to attempt a rewrite for you, but I can't make any promises as I don't fully understand what's happening in your code. However, I would like to point out that whilst you're free to do as you want with your model, the model in your case is acting as a controller which may make things difficult for you in the future. A model should ideally just return data. It should not load views. Pagination - El Forum - 03-01-2009 [eluser]Fero[/eluser] I see, anyway, I have edited my last (codings) post so I deleted everything you wouldn't need. Thank you Fuzzy for trying to help me Pagination - El Forum - 03-01-2009 [eluser]TheFuzzy0ne[/eluser] OK, here are my two proposed replacement functions: Code: <?php It may need a little bit of tweaking, but hopefully you can see that it's a bit easier to follow. The Database query is built as we progress down the function. I hope this helps, and this is at least close to what you were after. EDIT: The code needed changing to order articles by date, rather than id, which I've now done. EDIT2: Also, it looks like it will break when you click on the pagination if there is no category specified. I've added some code which should deal with this. Pagination - El Forum - 03-01-2009 [eluser]Fero[/eluser] ok read your edits, goin to try |