2013-01-21 53 views
-1

我知道這是很多要求得到非對象的屬性,但我有這樣的代碼:嘗試所有,雖然它確實存在

foreach($prices as $price){ 

$provider_id = $price->provider_id; 
$prod_id = $price->product_id; 
$name = $price->prod_name; 
$desc = $price->desc; 
$price = $price->price; 
$original_price = $price->original_price; 
$reward = $price->reward; 
    } 

現在,如果我print_r我得到它:

stdClass Object 
(
    [id] => 1214 
    [price_list_id] => 123 
    [product_id] => 136 
    [provider_id] => 1 
    [price] => 0 
    [reward] => 0 
    [original_price] => 135 
    [prod_name] => some text 
    [desc] => some text with ' and " and , 
) 

任何想法可能導致這種情況?我得到的錯誤上original_pricereward

+0

有什麼錯誤? –

+0

你傳遞給'print_r()'什麼變量? – nickb

+0

@ coder1984「試圖獲得非對象的財產」和尼克我傳球$價格 –

回答

5

這裏的錯誤,你有2 variables評爲循環$price

$price = $price->price; 

而且,

foreach($prices as $price){ 
+0

該死的havn't甚至沒有想過...謝謝! –

+0

不客氣:) –