2012-01-14 59 views
2

我在這裏面臨這個問題。我想通過從另一個表中獲取其項目ID來顯示項目的名稱。以下是代碼
我有問題,當我嘗試使用「。$ obj [0] - >名稱顯示名稱。」在for循環的第一行。注意:試圖獲得非物件的財產

$objClass = array(); 
$objClass1 = array(); 
$obj= array(); 
$object = new product(); 
$objLogic = new customerLogic(); 
$objLogic1 = new customerLogic(); 
$objL= new productLogic(); 
$objClass[0]= new stdClass; 
$objClass1[0]= new stdClass; 
$obj[0]= new stdClass; 
$objClass[0]->custId = $_GET['id']; 
$objClass1[0]->custId = $_GET['id']; 

$objClass = $objLogic->getSaleRecord_customer($objClass[0]); 
$objClass1 = $objLogic1->getName_customer($objClass1[0]); 
$object->itemId = $objClass[0]->itemId; 
$obj =$objL->getName_product($object->itemId); 
// echo $objClass1[0]->firstName; 
$i=1; 
foreach($objClass as $customer) { 
    echo "<tr><td class=\"inner_text\">$customer->reciept</td><td align=\"center\">".$obj[0]->name."</td>"; 
    echo "<td align=\"center\">".$objClass1[0]->firstName."&nbsp;".$objClass1[0]->lastName."</td><td align=\"center\">"; 
    echo "$customer->weight</td> 
    <td align=\"center\">$customer->costPerKg</td> 
    <td align=\"center\">$customer->cost</td> 
    <td align=\"center\">$customer->payed</td> 
    <td align=\"center\">$customer->remaining</td></tr>"; 
    $i++; 
} 
?> 
</table> 

回答

2

你完全確定$objL->getName_product($object->itemId);產生一個對象?

你能證實嗎?

我認爲$objL->getName_product($object->itemId);的返回值不是你認爲的那樣。

你可以通過print_r($objL->getName_product($object->itemId));來檢查它,它會給你打印輸出該功能的內容。

或者你也許無意中覆蓋了$obj的內容?

+0

這就是我使用 公共職能getName_product功能($對象) \t { \t \t $ dbHandler =新DBCONFIG(); \t \t $ query =「select item from product where itemId = $ object」; \t \t $ results = $ dbHandler-> Query($ query); \t \t return $ results; \t} – talhaMalik22 2012-01-14 22:11:45

+0

你確定這給你一個對象表示而不是關聯數組嗎?你有沒有試過'$ obj [0] ['name']'? – 2012-01-14 22:14:40

+0

哇..它不再顯示錯誤,但它也顯示了名稱?你能看到這裏的任何問題 – talhaMalik22 2012-01-14 22:17:52

0

您將要覆蓋$obj

$obj =$objL->getName_product($object->itemId); 
+0

對不起,我沒有得到你想說的話。我對PHP很陌生,你可以解釋一下我應該怎麼做 – talhaMalik22 2012-01-14 22:13:56

+1

@talha你正在使'$ obj'成爲一個對象,但是你會覆蓋上面的行。我不知道這條線應該做什麼,所以我不能給出任何真正的建議 - 也許你只需要刪除它或重命名變量 – 2012-01-14 22:15:43

+0

我得到了你的觀點,非常感謝它現在正在工作 – talhaMalik22 2012-01-14 22:24:42