Pagination |
[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?
[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).
[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");
[eluser]TheFuzzy0ne[/eluser]
OK, please repost your controller method and your model method.
[eluser]Fero[/eluser]
Controller (blog.php): Code: function kategoria() Model article.php: Code: function body($page,$category) //page-WHERE klauzula ; kategoria - category pointer
[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.
[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.
[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
[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.
|
Welcome Guest, Not a member yet? Register Sign In |