0

I am trying to retrieve data from database using CodeIgniter. The query works fine and retrieves data into an array which can be shown with print_array().

Array
(
[0] => Array
    (
        [trans_id] => 33
        [CustomerAccountNumber] => BR002
        [TransactionType] => Invoice
        [TransactionDate] => 2012-09-06 00:00:00
        [InvoiceNo] => 00001732262
        [OrderNo] => 0000183946
        [GoodsValueInAccountCurrency] => 1055.26
        [AccountBalance] => 1104.52
        [SYSTraderTranTypeID] => 4
    )

[1] => Array
    (
        [trans_id] => 34
        [CustomerAccountNumber] => BR002
        [TransactionType] => Invoice
        [TransactionDate] => 2012-09-19 00:00:00
        [InvoiceNo] => 00001375022
        [OrderNo] => 0000184907
        [GoodsValueInAccountCurrency] => 49.26
        [AccountBalance] => 1104.52
        [SYSTraderTranTypeID] => 4
    )

)

But whenever I try to display data within a table to generate pdf,it gives me an error stating "Trying to get property of non-object". But all the object are coming into an array to display. Here is my code:

    print_array($data['data']);
      {  foreach ($data['data'] as $key=>$link) 
        {
                {
                $html .= '
                <tr>
                   <td width = "100">'.$link->InvoiceNo.'</td>
                   <td width = "300">'.($link->OrderNo).'</td>
                   <td width = "100">'.($link->TransactionDate).'</td>
                   <td width = "100">'.($link->TransactionType).'</td>
                   <td width = "100">'.($link->GoodsValueInAccountCurrency).'</td>     
                </tr>';
                }



        }}

But this is giving me errors "Trying to get property of non-object". I am not getting any clue. Why? Please help.

4
  • Array ( [trans_id] => 34 [CustomerAccountNumber] => BAR004 [TransactionType] => Invoice [TransactionDate] => 2012-09-19 00:00:00 [InvoiceNo] => 0000175022 [OrderNo] => 0000184907 [GoodsValueInAccountCurrency] => 49.26 [AccountBalance] => 1104.52 [SYSTraderTranTypeID] => 4 ) Commented Mar 8, 2013 at 11:55
  • 1
    Try $link["key"] instead of $link->key Commented Mar 8, 2013 at 11:56
  • You are probably using result_array() function in CI to get the array. You can use result() to get the result array as object. Commented Mar 8, 2013 at 12:03
  • @Prashank.Thanks.you are right.I have sorted this one.Ta Commented Mar 8, 2013 at 13:08

1 Answer 1

1

You have an array and you are trying to access the property of an object. You should be using this syntax to build your table:

$html .= '
    <tr>
        <td width = "100">'.$link['InvoiceNo'].'</td>
        <td width = "300">'.($link['OrderNo']).'</td>
        <td width = "100">'.($link['TransactionDate']).'</td>
        <td width = "100">'.($link['TransactionType']).'</td>
        <td width = "100">'.($link['GoodsValueInAccountCurrency']).'</td>     
    </tr>';

$link->InvoiceNumber is the syntax to access an object property. $link['InvoiceNumber'] is the syntax to access an array element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.