Alfredo,

Thank you for finally responding.  I REALLY NEED HELP WITH THIS!!!!

I am not trying specify the return limit, I am trying to limit the
amount of characters returned from a field.  Say a field contains 500
characters, I only want the first 10.

I am having this problem with any SQL operators, like LEFT() and
DATE_FORMAT().

Following the example given in the documentation (http://
book.cakephp.org/view/449/find) I am writing this:

$this->Post->find('all',array('LEFT(Post.body,200) AS post_body'))

I have also tried this:

$this->Post->find('all',array('LEFT(Post.body,200) AS body'))

In my view I have this $post['Post']['body'] but I keep getting the
error Undefined index:  body

Any help would be greatly appreciated.



On Feb 5, 9:20 am, Alfredo Quiroga-Villamil <[email protected]> wrote:
> gkc:
>
> If I understood your question correctly what you want is something like 
> this???
>
> $aResult = $this->Model->find('all', array('limit' => 200));
>
> or something along those lines, specifying the field that you want, or
> the ones that you would like excluded.
>
> Regards,
>
> Alfredo
>
> On Wed, Feb 4, 2009 at 6:18 PM, gkc <[email protected]> wrote:
>
> > Can anybody help with this?
>
> > On Feb 4, 1:27 pm, gkc <[email protected]> wrote:
> >> This is according to the documentation:
>
> >> =====================================
> >> If you need to use SQL operators such as in (MySQL) DISTINCT, MAX,
> >> MIN, etc... you can specify it as part of the 'fields' key, as such:
> >>     $this->Product->find('all', array('fields'=>'DISTINCT
> >> (Product.name) AS product_name'));
>
> >> =====================================
>
> >> But that is not working for me.  I would rather limit in the query
> >> than passing it to PHP.  If thats my only option, then I will oblige
> >> but there has got to be a way to do this.
>
> >> On Feb 4, 11:47 am, czarcrab <[email protected]> wrote:
>
> >> > 2 ways about it.
>
> >> > One, switch on debug=1 (atleast) in core.php.  This should give you
> >> > the query and some indication on how to fix it.
>
> >> > Two, if the idea is to limit the amount of characters displayed in the
> >> > view, then handle it in the index.ctp like this
>
> >> > echo "<td>".(strlen($data['records'][$i][$field["table"]][$field
> >> > ["title"]]) > 25?substr($data['records'][$i][$field["table"]][$field
> >> > ["title"]],0,22)."...":$data['records'][$i][$field["table"]][$field
> >> > ["title"]] )."&nbsp;</td>";
>
> >> > On Feb 4, 12:28 pm, gkc <[email protected]> wrote:
>
> >> > > I need to limit the amount of characters returned on a field.
>
> >> > > I have tried using 'fields'=>array('LEFT(field,200) AS \'field\'') but
> >> > > I get an undefined index: field error when I do this.
>
> >> > > Any suggestions would be greatly appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to