Please don't post multiple threads for the same question.

$_this_id = $this->Post->field(
        'forum_id',
        array('Post.discussion_id' => $id)
);


But, if field() wouldn't work for some reason, there's always Set::extract().

$_this_id = Set::extract(
        $this->Post->find(
                'first',
                array(
                        'conditions' => array(
                                'Post.discussion_id'=>$id
                        ),
                        'fields'=>array('Post.forum_id')
                )
        ),
        '{n}.Post.forum_id'
);


On Sun, Aug 16, 2009 at 5:55 AM, albe<[email protected]> wrote:
>
> Hello everybody,
> I have this query:
>
> $_this_id = $this->Post->query("SELECT DISTINCT `forum_id` FROM
> `db`.`posts` WHERE `discussion_id` ='".$id."'");
>
> That gives me a result like this:
>
> Array
> (
>    [0] => Array
>        (
>            [posts] => Array
>                (
>                    [forum_id] => 1
>                )
>
>        )
>
> )
>
> But I want to obtain only the numeric result! (1)
>
> I've tried to use the find function in this way:
>
> $_this_id = $this->Post->find('first', array('conditions' =>array
> ('Post.discussion_id'=>$id), 'fields'=>array('Post.forum_id')));
>
> But when I try to print the result:
>
> pr($_this_id);
>
> I get a lot of errors of this kind:
>
> Notice: Undefined offset: 0 in C:\...\model\datasources\dbo_source.php
> on line 1283
>
> What is the reason?
> >
>

--~--~---------~--~----~------------~-------~--~----~
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