Login | Register
My pages Projects Community openCollabNet

Discussions > users > Having trouble with code: propel object a non-object

propel
Discussion topic

Back to topic list

Having trouble with code: propel object a non-object

Reply

Author "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com>
Full name "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com>
Date 2005-06-08 08:47:52 PDT
Message Hi.

 

Basically, what I am trying to do is update a few rows in a database, if one
value (symbol) in the rows are in my array. Here is my code. It’s very ugly.

 

The if($cp ===null) is negative, so $cp isn’t null.

 

The if(is_array) and the else are both false (how can that be!?) the else is
never run.

 

 

 

foreach($finalarray as $symbol => $price)

                        {

                                    $c = new Criteria();

 

 

 
$c->add(Currentp​ortfolioPeer::SYMBOL​,$symbol);

                                    

                                    $cp =
CurrentportfolioPeer​::doSelect($c);

                                    if($cp === null)

                                    {

                                                echo "null!!!";

                                                throw new Exception("Some
horrific error occurred");

                                    }

 

                                    //athugum hvort þetta sé array þ.e.
margir með sama symbol

                                    /* @var $cp CurrentPortfolio */

                                    if(is_array($cp))

                                    {

                                                foreach($cp as $item)

                                                {

                                                            echo "Fleiri en
einn: symbol er : " . $symbol;

 
$cp->setPrice($price);

                                                

                                                }

                                    }

 

                                    else

                                    {

                                                            echo "Einn:
symbol er : " . $symbol;

                                                $cp->setPrice($price);

                                    

                                    }

                                    

                                    $cp->save();

 

                        }

 

PHP says : Fatal error: Call to a member function save() on a non-object in
/var/www/devel/stock​s/stocks/StocksModul​e/StocksDataModule.p​hp on line 702

 

First, how can both the if and the else not be run. That isn’t supposed to
be possible? Is there a bracket mistake I can’t see there?

 

Any help is very welcome, I’m loosing my hair over this.
Attachments

« Previous message in topic | 1 of 6 | Next message in topic »

Messages

Show all messages in topic

Having trouble with code: propel object a non-object "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> 2005-06-08 08:47:52 PDT
     RE: Having trouble with code: propel object a non-object "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> 2005-06-08 09:03:39 PDT
     Re: [propel] Having trouble with code: propel object a non-object Georg Gell <georg_1 at have2 dot com> Georg Gell <georg_1 at have2 dot com> 2005-06-08 09:03:40 PDT
         RE: [propel] Having trouble with code: propel object a non-object "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> 2005-06-08 09:14:12 PDT
             RE: Having trouble with code: propel object a non-object "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> 2005-06-08 09:24:26 PDT
         RE: [propel] Having trouble with code: propel object a non-object "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> "=?iso-8859-1?Q?Hallgr=EDmur_Th dot _Bj=F6rnsson?=" <hallgrimur at gmail dot com> 2005-06-08 09:56:59 PDT
Messages per page: