ORDER BY id DESC
Hello, I've searched this group and all other resources (bakery, manual, book, API), but I found no useful results ... I have a table and that table contain some fields (it's only one table no HABTM here and no two tables relations): id . . catid . . I just mentioned the important fields ... and I have a function that takes $catId as parameter function getLastPost($catId) { $this-set('post', $this-Post-findByCatid($catId)); } this function return an array of results where the table field 'catid' = $catId (the parameter) what should i do to return only one result ordered by (table field) id desc, because I want only the one result with the last id (I want to use to show the last post from many categories) I mean something like that: SELECT * FROM posts WHERE catid = $catId ORDER BY id DESC; if I stick with this solution (give cake a query) ... cake returned an array based on 0,1,2,... locations but the API methods (find, findBy..) returned different array, based on table name instead of numbers I want a cakePHP function to do this query and return a will formated array: was that clear enough or not :S ?? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
If you're using CakePHP 1.1, something like this should do the job: $this-Post-findAll('catid = ' . $catid, array('field1'), 'id DESC', 1, 0); Don't forget to make sure that $catid is an integer. On 5/10/08, koko [EMAIL PROTECTED] wrote: Hello, I've searched this group and all other resources (bakery, manual, book, API), but I found no useful results ... I have a table and that table contain some fields (it's only one table no HABTM here and no two tables relations): id . . catid . . I just mentioned the important fields ... and I have a function that takes $catId as parameter function getLastPost($catId) { $this-set('post', $this-Post-findByCatid($catId)); } this function return an array of results where the table field 'catid' = $catId (the parameter) what should i do to return only one result ordered by (table field) id desc, because I want only the one result with the last id (I want to use to show the last post from many categories) I mean something like that: SELECT * FROM posts WHERE catid = $catId ORDER BY id DESC; if I stick with this solution (give cake a query) ... cake returned an array based on 0,1,2,... locations but the API methods (find, findBy..) returned different array, based on table name instead of numbers I want a cakePHP function to do this query and return a will formated array: was that clear enough or not :S ?? -- Sincerely yours, Olexandr Melnyk http://omelnyk.net/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
In 1.2 : $this-Post-find('first', array('conditions' = array('post.category_id' = intval($catId)), 'order' = 'post.id DESC')); On 10 mai, 13:39, Olexandr Melnyk [EMAIL PROTECTED] wrote: If you're using CakePHP 1.1, something like this should do the job: $this-Post-findAll('catid = ' . $catid, array('field1'), 'id DESC', 1, 0); Don't forget to make sure that $catid is an integer. On 5/10/08, koko [EMAIL PROTECTED] wrote: Hello, I've searched this group and all other resources (bakery, manual, book, API), but I found no useful results ... I have a table and that table contain some fields (it's only one table no HABTM here and no two tables relations): id . . catid . . I just mentioned the important fields ... and I have a function that takes $catId as parameter function getLastPost($catId) { $this-set('post', $this-Post-findByCatid($catId)); } this function return an array of results where the table field 'catid' = $catId (the parameter) what should i do to return only one result ordered by (table field) id desc, because I want only the one result with the last id (I want to use to show the last post from many categories) I mean something like that: SELECT * FROM posts WHERE catid = $catId ORDER BY id DESC; if I stick with this solution (give cake a query) ... cake returned an array based on 0,1,2,... locations but the API methods (find, findBy..) returned different array, based on table name instead of numbers I want a cakePHP function to do this query and return a will formated array: was that clear enough or not :S ?? -- Sincerely yours, Olexandr Melnykhttp://omelnyk.net/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
sorry I didn't mention that I'm using the latest 1.2.x from SVN (8/5/2208) anyway ... thanks very much ... but didn't find something like that anywhere I found how to pass a query thanks very much BTW... do you know how to set up a layout that contains many views (or actions behind them) with parameters in traditional php we used to do: include(header.php); include(getLastPost.php?catId=1) content here include(footer.php); how to do something like that in lovely cake :D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
I'm not sure what you mean by your last question, but what's wrong with using set()? On 5/10/08, koko [EMAIL PROTECTED] wrote: sorry I didn't mention that I'm using the latest 1.2.x from SVN (8/5/2208) anyway ... thanks very much ... but didn't find something like that anywhere I found how to pass a query thanks very much BTW... do you know how to set up a layout that contains many views (or actions behind them) with parameters in traditional php we used to do: include(header.php); include(getLastPost.php?catId=1) content here include(footer.php); how to do something like that in lovely cake :D -- Sincerely yours, Olexandr Melnyk http://omelnyk.net/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
I want to include many views into one view ... One big view contain many views (or actions) like a template ... there exist a topic in book 1.2 about how to template your email messages using set() Yeah set is working well but I just wanted to see if anyone has another way ,, but I think set() is the best for this case thanks everybody and thanks Christophe Cholot for your help it's nice to use this method too --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
See the FAQ (http://groups.google.co.uk/group/cake-php/web/faq) section How to display more views/blocks in a single page? On 10 May, 13:35, koko [EMAIL PROTECTED] wrote: I want to include many views into one view ... One big view contain many views (or actions) like a template ... there exist a topic in book 1.2 about how to template your email messages using set() Yeah set is working well but I just wanted to see if anyone has another way ,, but I think set() is the best for this case thanks everybody and thanks Christophe Cholot for your help it's nice to use this method too --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: ORDER BY id DESC
ًWAW ... I haven't seen this FAQ before !!! it's very nice ... danke On May 10, 5:36 pm, the_woodsman [EMAIL PROTECTED] wrote: See the FAQ (http://groups.google.co.uk/group/cake-php/web/faq) section How to display more views/blocks in a single page? On 10 May, 13:35, koko [EMAIL PROTECTED] wrote: I want to include many views into one view ... One big view contain many views (or actions) like a template ... there exist a topic in book 1.2 about how to template your email messages using set() Yeah set is working well but I just wanted to see if anyone has another way ,, but I think set() is the best for this case thanks everybody and thanks Christophe Cholot for your help it's nice to use this method too --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---