Page 1 of 1

Fatal error: Cannot use [] for reading in

Posted: Sun Nov 20, 2011 2:48 am
by jone kent
Hello i am new here also new in php

i have problem with my code

Code: Select all

    $seller_id = $listings[]['Account_ID'];
    $seller_info = $rlAccount -> getProfileInfo( $seller_id );
    $rlSmarty -> assign_by_ref( 'seller_info', $seller_info ); 
i get this error Fatal error: Cannot use [] for reading in

the array is

Code: Select all

    Array (
    [0] => Array
    (
    [name] => Automobiles
    [ID] => 1
    [Account_ID] => 0
    )
    [1] => Array
    (
    [name] => Automobiles
    [ID] => 2
    [Account_ID] => 1
    )
    )
    .
    .
    . 
Please help how i can fix it

Re: Fatal error: Cannot use [] for reading in

Posted: Sun Nov 20, 2011 4:47 am
by twinedev
You must provide an index for every level of an array, the only time you can use [] is when you are adding an item to an array, then it will auto use the next number index available.

you will need to provice the index for the item you are wanting

Code: Select all

$seller_id = $listings[0]['Account_ID'];
-Greg

Re: Fatal error: Cannot use [] for reading in

Posted: Sun Nov 20, 2011 12:24 pm
by jone kent
i tried this one but it's not work for me, its give me listing number 0

Re: Fatal error: Cannot use [] for reading in

Posted: Sun Nov 20, 2011 8:31 pm
by McInfo
For an aide to my example, here is an array of names grouped by street and house numbers.

Code: Select all

$occupants_by_address = array (
    '30th Street' => array (
        'Number 13' => 'Bill Jones',
        'Number 25' => 'Portia Caine',
    ),
    '42nd Street' => array (
        'Number 13' => 'Amanda Howard',
        'Number 7' => 'Bryce Hardin',
    ),
);
You can ask the question "Who lives on 30th Street at Number 13?" In code, the question would be represented as

Code: Select all

echo $occupants_by_address['30th Street']['Number 13']; // Bill Jones
The answer would be Bill Jones.

However, the question "Who lives at Number 13?" is unanswerable because no street was specified.

Code: Select all

echo $occupants_by_address[]['Number 13']; // Wrong - no street specified
Both Bill Jones and Amanda Howard live at Number 13, but it's not the same Number 13 because the streets are different.

If you want a better answer, you will have to show us more code or further explain what your code is supposed to do.

Re: Fatal error: Cannot use [] for reading in

Posted: Sun Nov 20, 2011 11:27 pm
by twinedev
jone kent wrote:i tried this one but it's not work for me, its give me listing number 0
Exactly, the sample I gave specified the index 0. You didn't say which one you wanted, so I just gave an example. Change the 0 to the one you want.

Re: Fatal error: Cannot use [] for reading in

Posted: Mon Nov 21, 2011 2:07 am
by jone kent
Ok i attached 2 files for this code, what i want is to get listing with seller name and seller image for each listing

Re: Fatal error: Cannot use [] for reading in

Posted: Tue Nov 22, 2011 12:02 pm
by jone kent
can anyone help me???

Re: Fatal error: Cannot use [] for reading in

Posted: Tue Nov 22, 2011 3:02 pm
by pickle
Your question has been answered. You cannot use [] for reading - its a write operator. If you want to read, you have to provide an index. While [] and, say, [0] may look similar, they do completely different things.

Re: Fatal error: Cannot use [] for reading in

Posted: Tue Nov 22, 2011 3:52 pm
by twinedev

Code: Select all

$strInfo = '';
foreach($listings as $aryItem) {
    $seller_info = $rlAccount->getProfileInfo($aryItem['Account_ID']);
    // You will need to code this for how you want to string them togeher...
    $strInfo .= $seller_info . "<br>\n";
}
$rlSmarty -> assign_by_ref( 'seller_info', $strInfo ); 

Re: Fatal error: Cannot use [] for reading in

Posted: Sat Nov 26, 2011 4:28 am
by jone kent
twinedev wrote:

Code: Select all

$strInfo = '';
foreach($listings as $aryItem) {
    $seller_info = $rlAccount->getProfileInfo($aryItem['Account_ID']);
    // You will need to code this for how you want to string them togeher...
    $strInfo .= $seller_info . "<br>\n";
}
$rlSmarty -> assign_by_ref( 'seller_info', $strInfo ); 
Sorry it not working :(