Re: Query using LEFT()

2009-02-05 Thread Miles J

Why dont you just truncate after the result?
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread AD7six


On Feb 5, 9:03 pm, gkc  wrote:
> AD7six:
>
> Thanks for pointing out the debug.
>
> Here is what is coming up:
>
> Array
> (
>     [0] => Array
>         (
>             [Post] => Array
>                 (
>                     [title] => This is the first Post
>                     [tag] => architect, costs
>                     [created] => 2009-02-05 10:58:11
>                 )
>
>             [0] => Array
>                 (
>                     [body] => here
>                 )
>
>             [User] => Array
>                 (
>                     [username] =>
>                 )
>
>         )
>
>     [1] => Array
>         (
>             [Post] => Array
>                 (
>                     [title] => This is the second post
>                     [tag] => subcontractor
>                     [created] => 2009-02-04 10:58:38
>                 )
>
>             [0] => Array
>                 (
>                     [body] => this
>                 )
>
>             [User] => Array
>                 (
>                     [username] =>
>                 )
>
>         )
>
> )
>
> Why would it come up as 0 and not under Post?

Because according to the db calculated fields don't belong to a table.

hth,

AD
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread gkc

AD7six:

Thanks for pointing out the debug.

Here is what is coming up:

Array
(
[0] => Array
(
[Post] => Array
(
[title] => This is the first Post
[tag] => architect, costs
[created] => 2009-02-05 10:58:11
)

[0] => Array
(
[body] => here
)

[User] => Array
(
[username] =>
)

)

[1] => Array
(
[Post] => Array
(
[title] => This is the second post
[tag] => subcontractor
[created] => 2009-02-04 10:58:38
)

[0] => Array
(
[body] => this
)

[User] => Array
(
[username] =>
)

)

)


Why would it come up as 0 and not under Post?

gkc


On Feb 5, 12:31 pm, AD7six  wrote:
> On Feb 5, 7:24 pm, gkc  wrote:
>
> > Siegfried:
>
> > I was using 1.2.0.7962 but I just downloaded the latest version.
>
> > I dont think its a problem with the query itself because I dont get
> > any SQL error messages.  I think it is how its being reference in the
> > view.  How would you reference the return p10 in your view?  I keep
> > getting Undefined index:  body when using $post['Post']['body'].
>
> > Thanks for the help!
>
> How aboug debug ($post); die; and looking?
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread AD7six



On Feb 5, 7:24 pm, gkc  wrote:
> Siegfried:
>
> I was using 1.2.0.7962 but I just downloaded the latest version.
>
> I dont think its a problem with the query itself because I dont get
> any SQL error messages.  I think it is how its being reference in the
> view.  How would you reference the return p10 in your view?  I keep
> getting Undefined index:  body when using $post['Post']['body'].
>
> Thanks for the help!

How aboug debug ($post); die; and looking?
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread gkc

Siegfried:

I was using 1.2.0.7962 but I just downloaded the latest version.

I dont think its a problem with the query itself because I dont get
any SQL error messages.  I think it is how its being reference in the
view.  How would you reference the return p10 in your view?  I keep
getting Undefined index:  body when using $post['Post']['body'].

Thanks for the help!

On Feb 5, 11:54 am, Siegfried Hirsch 
wrote:
> Hello gkc,
>
> I have just tried the following in my app:
>
> $vendors = $this->find('all',
>                                array('conditions'=>array('vendor_id >' => 0),
>                                      'contain'=>array('Vendor.shortname'),
>
> 'fields'=>array('left(Item.product,10) as p10, COUNT(*) as count'), //
> 'Item.vendor_id,
>                                      'group'=>array('Item.vendor_id'),
>                                      'order'=>array('COUNT(*) desc'),
>                                      //'recursive'=>-1,
>                                      )
>                                );
>
> This works like a charm for me.
>
> Array
> (
>     [0] => Array
>         (
>             [0] => Array
>                 (
>                     [p10] => 6ES5721-0C
>                     [count] => 3173
>                 )
>
>             [Vendor] => Array
>                 (
>                     [shortname] => XYZ
>                     [id] => 377
>                 )
>
>         )
>
>     [1] => Array
>         (
>             [0] => Array
>                 (
>                     [p10] => POG90 2048
>                     [count] => 404
>                 )
>
>             [Vendor] => Array
>                 (
>                     [shortname] => Tha
>                     [id] => 35
>                 )
>
>         )
>
> Which version of cake are you using ?
>
> On Thu, Feb 5, 2009 at 6:35 PM, gkc  wrote:
>
> > Alfredo,
>
> > Thank you for finally responding.  I REALLY NEED HELP WITH THIS
>
> Dont cry ;)
>
> Siegfried
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread Siegfried Hirsch

Hello gkc,

I have just tried the following in my app:

$vendors = $this->find('all',
   array('conditions'=>array('vendor_id >' => 0),
 'contain'=>array('Vendor.shortname'),

'fields'=>array('left(Item.product,10) as p10, COUNT(*) as count'), //
'Item.vendor_id,
 'group'=>array('Item.vendor_id'),
 'order'=>array('COUNT(*) desc'),
 //'recursive'=>-1,
 )
   );

This works like a charm for me.

Array
(
[0] => Array
(
[0] => Array
(
[p10] => 6ES5721-0C
[count] => 3173
)

[Vendor] => Array
(
[shortname] => XYZ
[id] => 377
)

)

[1] => Array
(
[0] => Array
(
[p10] => POG90 2048
[count] => 404
)

[Vendor] => Array
(
[shortname] => Tha
[id] => 35
)

)

Which version of cake are you using ?


On Thu, Feb 5, 2009 at 6:35 PM, gkc  wrote:
>
> Alfredo,
>
> Thank you for finally responding.  I REALLY NEED HELP WITH THIS
Dont cry ;)

Siegfried

--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread gkc

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  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  wrote:
>
> > Can anybody help with this?
>
> > On Feb 4, 1:27 pm, gkc  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  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 "".(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"]] )." ";
>
> >> > On Feb 4, 12:28 pm, gkc  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-05 Thread Alfredo Quiroga-Villamil

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  wrote:
>
> Can anybody help with this?
>
> On Feb 4, 1:27 pm, gkc  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  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 "".(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"]] )." ";
>>
>> > On Feb 4, 12:28 pm, gkc  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-04 Thread gkc

Can anybody help with this?

On Feb 4, 1:27 pm, gkc  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  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 "".(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"]] )." ";
>
> > On Feb 4, 12:28 pm, gkc  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-04 Thread gkc

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  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 "".(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"]] )." ";
>
> On Feb 4, 12:28 pm, gkc  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Query using LEFT()

2009-02-04 Thread czarcrab

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 "".(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"]] )." ";


On Feb 4, 12:28 pm, gkc  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 cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---