Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: PHP/XML code issue

date posted 27th April 2007 16:15

If $name_array is an array, the $url_array will *always* be and array,
with an equal number of elements.

Each array will contain the name/url of the current node, and the
name/url of each parent node back to root level.

- deanoj

Dave Fennell wrote:
>
>
>
> Deano J wrote:
>> Hi all
>>
>> Can someone offer some advice on the following?
>>
>> When viewing my site very occasionally PHP gives me the following
>> notices...
>>
>> ============
>> Notice: Undefined offset: 0 in /var/www/dj2/classes/nav.class.php on
>> line 87
>> Notice: Undefined offset: 1 in /var/www/dj2/classes/nav.class.php on
>> line 87
>> Notice: Undefined offset: 2 in /var/www/dj2/classes/nav.class.php on
>> line 87
>> ...
>> ============ continues up to xml total entries
>>
>> The code this references is...
>> ============
>> public function breadcrumbs($node) {
>> $name_array =
>> $this->xml->xpath("//siteMapNode[name='$node']/ancestor::*/name");
>> $url_array =
>> $this->xml->xpath("//siteMapNode[name='$node']/ancestor::*/url");
>> if ($node == "Home") {
>> $this->output = "> ";
>> } else {
>> $this->output = "Home >\n";
>> }
>> if (is_array($name_array)) {
>> foreach($name_array as $key=>$value) {
>> **87** $link = $url_array[$key];
>> $link = str_replace("~","",$link);
>> $this->output .= "$value > \n";
>> }
>> } else {
>> $this->output .= "";
>> }
>> $this->output .= "$node \n\n";
>> return $this->output;
>> }
>> =============
>> Normally I have no problems and the code works as expected giving a nice
>> formatted
>>
>> Home > Link1 > Link2
>>
>> but say every 1 in 20 refreshes I get the php notice messages, and the
>> navigation links go nuts showing every link in the file regardless of
>> structure. (about 25)
>>
>> Even stranger when I look at the source in firefox this is not shown. In
>> fact none of the links are in the source apart from the first static
>> one!!!
>>
>> I have not yet managed to mimic this behavior in internet explorer.
>>
>> The error seems to be indicating some kind of XPATH failure to pass the
>> correct values to the 'name' and 'url' arrays. Anyone have any clue why?
>>
>> - thanks - deanoj
>>
>>
>>
> In the code:
>
> if (is_array($name_array)) {
>
> foreach($name_array as $key=>$value) {
> **87** $link = $url_array[$key];
> $link = str_replace("~","",$link);
> $this->output .= "$value > \n";
> }
> } else {
> $this->output .= "";
> }
>
> You only check that name_array is an array, but in the loop you access
> "url_array" assuming it too is an array and has the same number of
> elements as "name_array".
>
> An obvious fix would be :
>
> if (is_array($name_array) && is_array($url_array)) {
>
>
> That would remove the error, but are you saying that they should
> *always* be the same?
>
> Dave
>
>



Messages by Day
April 30th 2007
April 29th 2007
April 28th 2007
April 27th 2007
April 26th 2007
April 25th 2007
April 24th 2007
April 23rd 2007
April 22nd 2007
April 21st 2007
April 20th 2007
April 19th 2007
April 18th 2007
April 17th 2007
April 16th 2007
April 15th 2007
April 14th 2007
April 13th 2007
April 12th 2007
April 11th 2007
April 10th 2007
April 9th 2007
April 8th 2007
April 7th 2007
April 6th 2007
April 5th 2007
April 4th 2007
April 3rd 2007
April 2nd 2007
April 1st 2007


Messages by Month
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000