1
wtravel
New Amazon module - Undefined index problem

Hi,

I am working on a new Amazon module and got one loose end untill now.

This line leads to an error, but I am not sure how to define ErrorMsg as an index in this case.
Quote:

if($d_ar[$i_ar['ErrorMsg'][0]]['type']=='open' || $d_ar[$i_ar['ErrorMsg'][0]]['type']=='complete'){ // no results were found from the search

It leads to the following notices in PHP debug:
Quote:
Notice [PHP]: Undefined index: ErrorMsg in file modules/destinations/books.php line 149
Notice [PHP]: Undefined index: in file modules/destinations/books.php line 149
Notice [PHP]: Undefined index: ErrorMsg in file modules/destinations/books.php line 149
Notice [PHP]: Undefined index: in file modules/destinations/books.php line 149
Who can tell me the solution for this (other than turning PHP debug off )?

2
Mithrandir
Re: New Amazon module - Undefined index problem

depends on how you put the data into the $i_arr array.

3
wtravel
Re: New Amazon module - Undefined index problem

Hi,

It is coming from:
Quote:
xml_parse_into_struct($parser,$data,&$d_ar,&$i_ar);

Quote:
$data = @implode("",file($xmlFeed));

Quote:
$xmlFeed = 'http://xml.amazon.com/onca/xml3?t=' .$AssociatesID;
$xmlFeed .= '&dev-t=' .$DevToken;
$xmlFeed .= '&' .$SearchType;
$xmlFeed .= '=' .$SearchString;
$xmlFeed .= '&mode=' .$Mode;
$xmlFeed .= '&sort=' .$Sort;
$xmlFeed .= '&offer=All&type=' .$Type;
$xmlFeed .= '&page=' .$Page. '&f=xml';

edited: So if for example this line is in the xml output it is no problem:Quote:
<ErrorMsg>There are no exact matches for the search.</ErrorMsg>

But this line is not in the xml output if there is no error.

Martijn




4
Mithrandir
Re: New Amazon module - Undefined index problem

erhm... I ask where you get the $i_arr from and you show where it is used in a function call?

How do you get the $i_arr to send with the function?

But wouldn't it solve it if you put in this:
if (isset($i_arr['ErrorMsg']) {
   
//previous code
}

(sorry if it doesn't match your original code, can't remember the original code)

5
wtravel
Re: New Amazon module - Undefined index problem

Mithrandir,

Thanks, this did the trick.

Quote:
if (isset($i_arr['ErrorMsg'])) {
}

The function I showed you is a standard php function, $i_arr is not declared before that function but is declared with the outcome, like with this example:
Quote:

$simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);

I tried something similar to what you showed but did not leave out the other array element, which caused the error.

Regards,

Martijn