TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   cant work this error out (http://www.talkphp.com/absolute-beginners/4682-cant-work-error-out.html)

talonos 07-04-2009 03:24 PM

cant work this error out
 
ok i've been working on a world of warcraft armory parser for achievements and for some reason its showing an error even thou the other pages i have just like this one work fine

CODE:
PHP Code:

#!/usr/bin/php 
<?php 


// Include phpbb's config for db info 
//include("config.php"); 

echo 'Working...' '</br>'

/* 
roster_gen class posted by D1g1talS0ul on elitistjerks.com 
*/ 

class roster_gen 

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3"

 public 
$query
 public 
$server
 public 
$guild
 public 
$guildie
 public 
$page

public function 
__construct $query$server$guild$guildie$page ) { 
    
$this->query $query
    
$this->server $server
    
$this->guild $guild
    
$this->guildie $guildie
    
$this->page $page
 } 
// end of __construct() 

public function pull_xml() { 

    if( 
$this->query === 'roster' ) { 
        
$url 'http://eu.wowarmory.com/guild-info.xml?r=' $this->server '&n=' $this->guild'&p=' $this->page
         
    } elseif( 
$this->query === 'character' ) { 
        
$url 'http://eu.wowarmory.com/character-sheet.xml?r=' $this->server '&n=' $this->guildie
     
    } elseif( 
$this->query === 'achievements' ) { 
        
$url 'http://eu.wowarmory.com/character-achievements.xml?r=' $this->server '&cn=' $this->guildie '&gn=' .  
            
$this->guild '&c=168'
    } 

    
$ch curl_init(); 
    
curl_setopt ($chCURLOPT_URL$url); 
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
    
curl_setopt ($chCURLOPT_CONNECTTIMEOUT60); 
    
curl_setopt ($chCURLOPT_USERAGENT,  roster_gen::BROWSER); 
     
    
$url_string curl_exec($ch); 

    return 
simplexml_load_string($url_string); 
     
    
curl_close($ch); 
 } 
// end of pull_xml() 

// end class 

$roster = new roster_gen ('roster''stormrage''heroes+of+warcraft'NULL1); 
$xml_roster $roster->pull_xml(); 


// Change to querying achievements 
$roster->query=achievements

// Set up the member array 
$member_data = array(); 
$id 0


foreach (
$xml_roster->guildInfo->guild->members->character as $char

    if (
$char['level'] == 80 && $char['rank'] <= '2' ) { 

        
$roster->guildie $char['name']; 
         
        
$xml_char $roster->pull_xml(); 

        
$ach find_category($xml_char->category); 

        
$a = array(); 

        
$a[0] = check_achievement($ach0); 
        
$a[1] = check_achievement($ach1); 
        
$a[2] = check_achievement($ach2); 
        
$a[3] = check_achievement($ach3); 
        
$a[4] = check_achievement($ach4); 
        
$a[5] = check_achievement($ach5); 

         
        
$member_data[$id] = array( 
                                
'name' => $char['name'], 
                                
'0' => $a[0], 
                                
'1' => $a[1], 
                                
'2' => $a[2], 
                                
'3' => $a[3], 
                                
'4' => $a[4], 
                                
'5' => $a[5]
                                ); 
                                 
        
// Provide some output that it's doing stuff 
        
echo 'Updated: <b>' $char['name'] . '</b> ' $a[0] . '-' $a[1] . '-' $a[2] . '-' $a[3] . '-' $a[4] . '-' $a[5] . '</br>'
                                 
        
$id++;                         
    } 
     
}  
/*
echo '</br>Inserting values into DB...</br>'; 

// Connect to the DB 
$db = mysql_connect($dbhost, $dbuser, $dbpasswd); 
$db_selected = mysql_select_db($dbname, $db); 

foreach ($member_data as $member) 

    $name = $member['name']; 

    $sql = "insert into ach_data2(name, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)  
       VALUES ('$name', '$a[0]', '$a[1]', '$a[2]', '$a[3]', '$a[4]', '$a[5]', '$a[6]', '$a[7]', '$a[8]', '$a[9]', '$a[10]', '$a[11]', '$a[12]', '$a[13]', '$a[14]')"; 
    $result = mysql_query($sql); 
     
   if(!$result); 
       echo mysql_error() . "\n";     


echo 'Database update completed.'; 
*/

function find_category($xml

    foreach(
$xml->achievement as $ach) { 
        if(
$ach['id'] == 576
            return 
$ach
    } 



function 
check_achievement($achievement$num) { 
if(
$achievement ['dateCompleted'] != NULL)
        return 
1;
        else
    if(
$achievement->criteria[$num]['date'] != NULL
        return 
1
    else 
        return 
0


?>

mysql access is disabled until error is fixed,
the error i'm recieving is when i update the script it send me this
HTML Code:

#!/usr/bin/php
Working...</br><br />
<b>Notice</b>:  Use of undefined constant achievements - assumed 'achievements' in <b>C:\wamp\www\ulduar.php</b> on line <b>65</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\wamp\www\ulduar.php</b> on line <b>144</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\wamp\www\ulduar.php</b> on line <b>144</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\wamp\www\ulduar.php</b> on line <b>144</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\wamp\www\ulduar.php</b> on line <b>144</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\wamp\www\ulduar.php</b> on line <b>144</b><br />
<br />
<b>Notice</b>:  Trying to get property of non-object in <b>C:\wamp\www\ulduar.php</b> on line <b>144</b><br />
Updated: <b>Goll</b> 0-0-0-0-0-0</br><br />

and the same for ALL the other things its meant to list too :-(

does anyone know how to rectify this error at all

any help is appreciated
thanks in advance

Talonos

talonos 07-04-2009 03:27 PM

ohh btw this is the sort of content its trying to parse from

Code:

      <achievement categoryId="168" dateCompleted="2009-06-15+02:00" desc="Defeat Kel'Thuzad on Normal Difficulty in Naxxramas." icon="inv_trinket_naxxramas06" id="574" points="10" title="Kel'Thuzad's Defeat"/>
      <achievement categoryId="168" dateCompleted="2009-06-15+02:00" desc="Defeat every boss in Naxxramas on Normal Difficulty." icon="achievement_dungeon_naxxramas_normal" id="576" points="25" title="The Fall of Naxxramas">
        <criteria name="The Arachnid Quarter"/>
        <criteria name="The Construct Quarter"/>
        <criteria name="The Plague Quarter"/>
        <criteria name="The Military Quarter"/>
        <criteria name="Sapphiron's Demise"/>
        <criteria name="Kel'Thuzad's Defeat"/>
      </achievement>


adamdecaf 07-04-2009 05:09 PM

Well, it will fail in trying to parse the data between,

Code:

<criteria name="The Arachnid Quarter"/>
<criteria name="The Construct Quarter"/>

because it's not a in the standard simple xml format.

Code:

<criteria>The Arachnid Quarter</criteria>
<criteria>The Construct Quarter</criteria>

It looks like your going to need to use some advanced simplexml, and add some attributes to parse it correctly.

talonos 07-04-2009 05:26 PM

thing is thou this script is the same as my others and they are working fine even with the <criteria issue that u say might be breaking it

adamdecaf 07-04-2009 05:51 PM

Can you post a copy of the HTML source? It will help me pinpoint where in the PHP it's failing.

talonos 07-04-2009 06:00 PM

my read file:

PHP Code:

#!/usr/bin/php 
<?php 

/* 



// Include phpbb's config for db info 
//include("config.php"); 

echo 'Working...' . '</br>'; 

/* 
roster_gen class posted by D1g1talS0ul on elitistjerks.com 
*/ 

class roster_gen 

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3"

 public 
$query
 public 
$server
 public 
$guild
 public 
$guildie
 public 
$page

public function 
__construct $query$server$guild$guildie$page ) { 
    
$this->query $query
    
$this->server $server
    
$this->guild $guild
    
$this->guildie $guildie
    
$this->page $page
 } 
// end of __construct() 

public function pull_xml() { 

    if( 
$this->query === 'roster' ) { 
        
$url 'http://eu.wowarmory.com/guild-info.xml?r=' $this->server '&n=' $this->guild'&p=' $this->page
         
    } elseif( 
$this->query === 'character' ) { 
        
$url 'http://eu.wowarmory.com/character-sheet.xml?r=' $this->server '&n=' $this->guildie
     
    } elseif( 
$this->query === 'achievements' ) { 
        
$url 'http://eu.wowarmory.com/character-achievements.xml?r=' $this->server '&cn=' $this->guildie '&gn=' .  
            
$this->guild '&c=168'
    } 

    
$ch curl_init(); 
    
curl_setopt ($chCURLOPT_URL$url); 
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
    
curl_setopt ($chCURLOPT_CONNECTTIMEOUT60); 
    
curl_setopt ($chCURLOPT_USERAGENT,  roster_gen::BROWSER); 
     
    
$url_string curl_exec($ch); 

    return 
simplexml_load_string($url_string); 
     
    
curl_close($ch); 
 } 
// end of pull_xml() 

// end class 

$roster = new roster_gen ('roster''stormrage''heroes+of+warcraft'NULL1); 
$xml_roster $roster->pull_xml(); 


// Change to querying achievements 
$roster->query='achievements'

// Set up the member array 
$member_data = array(); 
$id 0


foreach (
$xml_roster->guildInfo->guild->members->character as $char

    if (
$char['level'] == 80 && $char['rank'] <= '3' ) { 

        
$roster->guildie $char['name']; 
         
        
$xml_char $roster->pull_xml(); 

        
$ach find_category($xml_char->category); 

        
$a = array(); 

        
$a[0] = check_achievement($ach0); 
        
$a[1] = check_achievement($ach1); 
        
$a[2] = check_achievement($ach2); 
        
$a[3] = check_achievement($ach3); 
        
$a[4] = check_achievement($ach4); 
        
$a[5] = check_achievement($ach5); 

         
        
$member_data[$id] = array( 
                                
'name' => $char['name'], 
                                
'0' => $a[0], 
                                
'1' => $a[1], 
                                
'2' => $a[2], 
                                
'3' => $a[3], 
                                
'4' => $a[4], 
                                
'5' => $a[5
                                ); 
                                 
        
// Provide some output that it's doing stuff 
       
echo 'Updated: <b>' $char['name'] . '</b> ' $a[0] . '-' $a[1] . '-' $a[2] . '-' $a[3] . '-' $a[4] . '-' $a[5] . '</br>'
                                 
        
$id++;                         
    } 
     
}  
/*
echo '</br>Inserting values into DB...</br>'; 

// Connect to the DB 
$db = mysql_connect($dbhost, $dbuser, $dbpasswd); 
$db_selected = mysql_select_db($dbname, $db); 

foreach ($member_data as $member) 

    $name = $member['name']; 

    $sql = "insert into ach_data(name, a0, a1, a2, a3, a4, a5)
       VALUES ('$name', '$member[0]', '$member[1]', '$member[2]', '$member[3]', '$member[4]', '$member[5]')"; 
    $result = mysql_query($sql); 
     
   if(!$result); 
       echo mysql_error() . "\n";     


echo 'Database update completed.'; 
*/

function find_category($xml

    foreach(
$xml->achievement as $ach) { 
        if(
$ach['id'] == 576
            return 
$ach
    } 



function 
check_achievement($achievement$num) {
if(
$achievement ['dateCompleted'] != NULL)
        return 
1;
        else 
    if(
$achievement->criteria[$num]['date'] != NULL
        return 
1
    else 
        return 
0


?>

source XML file is

http://eu.wowarmory.com/character-ac...warcraft&c=168

to find the area i might be having problems in the xml file just search for
Code:

576
and look between the
Code:

[acheivement][/achievment]
tags, my read file is the ONLY code i use except a few settings in a config which are for mysql only anyways

Code:

function check_achievement($achievement, $num) {
if($achievement ['dateCompleted'] != NULL)
        return 1;
                else
    if($achievement->criteria[$num]['date'] != NULL)
        return 1;
    else
        return 0;

seems to be the area where the problem is and the error its kicking out is

Code:

Notice: Trying to get property of non-object in C:\wamp\www\ulduar.php on line 163

Notice: Trying to get property of non-object in C:\wamp\www\ulduar.php on line 163

Notice: Trying to get property of non-object in C:\wamp\www\ulduar.php on line 163

Notice: Trying to get property of non-object in C:\wamp\www\ulduar.php on line 163

Notice: Trying to get property of non-object in C:\wamp\www\ulduar.php on line 163

Notice: Trying to get property of non-object in C:\wamp\www\ulduar.php on line 163
Updated: Rabbitpt 0-0-0-0-0-0


rguy84 07-05-2009 08:00 PM

Did you now get this working? I clicked your link. In:
Opera - you get a text nightmare.
Firefox - same
IE8 - renders the (ugly) HTML.

You need some more standard tags. Namely the html and body. Or xml...

adamdecaf 07-05-2009 08:03 PM

The output is XML...

It's gotta be the way you parse the XML. I just can't find it.

talonos 07-05-2009 11:55 PM

in IE8 click "view source" to see the xml data and i've still not fixed the error :(

talonos 07-06-2009 12:03 AM

i've already got one page that parses that same xml file but a diffrent part and the layout is the exact same with the criteria but that page doesn't have the error at all, but this one is and its really starting to annoying me now as quite a few people cant work it out either even thou theres very little diffrence within the 2 pages, i'll post my working script so u guys can compare and see if u can work it out too


PHP Code:

#!/usr/bin/php 
<?php 


 

// Include phpbb's config for db info 
//include("config.php"); 

echo 'Working...' '</br>'

/* 
roster_gen class posted by D1g1talS0ul on elitistjerks.com 
*/ 

class roster_gen 

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3"

 public 
$query
 public 
$server
 public 
$guild
 public 
$guildie
 public 
$page

public function 
__construct $query$server$guild$guildie$page ) { 
    
$this->query $query
    
$this->server $server
    
$this->guild $guild
    
$this->guildie $guildie
    
$this->page $page
 } 
// end of __construct() 

public function pull_xml() { 

    if( 
$this->query === 'roster' ) { 
        
$url 'http://eu.wowarmory.com/guild-info.xml?r=' $this->server '&n=' $this->guild'&p=' $this->page
         
    } elseif( 
$this->query === 'character' ) { 
        
$url 'http://eu.wowarmory.com/character-sheet.xml?r=' $this->server '&n=' $this->guildie
     
    } elseif( 
$this->query === 'achievements' ) { 
        
$url 'http://eu.wowarmory.com/character-achievements.xml?r=' $this->server '&cn=' $this->guildie '&gn=' .  
            
$this->guild '&c=168'
    } 

    
$ch curl_init(); 
    
curl_setopt ($chCURLOPT_URL$url); 
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1); 
    
curl_setopt ($chCURLOPT_CONNECTTIMEOUT60); 
    
curl_setopt ($chCURLOPT_USERAGENT,  roster_gen::BROWSER); 
     
    
$url_string curl_exec($ch); 

    return 
simplexml_load_string($url_string); 
     
    
curl_close($ch); 
 } 
// end of pull_xml() 

// end class 

$roster = new roster_gen ('roster''stormrage''heroes+of+warcraft'NULL1); 
$xml_roster $roster->pull_xml(); 


// Change to querying achievements 
$roster->query='achievements'

// Set up the member array 
$member_data = array(); 
$id 0


foreach (
$xml_roster->guildInfo->guild->members->character as $char

    if (
$char['level'] == 80 && $char['name'] != 'chiyome' ) { 

        
$roster->guildie $char['name']; 
         
        
$xml_char $roster->pull_xml(); 

        
$ach find_category($xml_char->category); 

        
$a = array(); 

        
$a[0] = check_achievement($ach0); 
        
$a[1] = check_achievement($ach1); 
        
$a[2] = check_achievement($ach2); 
        
$a[3] = check_achievement($ach3); 
        
$a[4] = check_achievement($ach4); 
        
$a[5] = check_achievement($ach5); 
        
$a[6] = check_achievement($ach6); 
        
$a[7] = check_achievement($ach7); 
        
$a[8] = check_achievement($ach8); 
        
$a[9] = check_achievement($ach9); 
        
$a[10] = check_achievement($ach10);         
        
$a[11] = check_achievement($ach11); 
        
$a[12] = check_achievement($ach12); 
        
$a[13] = check_achievement($ach13); 
        
$a[14] = check_achievement($ach14); 
         
        
$member_data[$id] = array( 
                                
'name' => $char['name'], 
                                
'0' => $a[0], 
                                
'1' => $a[1], 
                                
'2' => $a[2], 
                                
'3' => $a[3], 
                                
'4' => $a[4], 
                                
'5' => $a[5], 
                                
'6' => $a[6], 
                                
'7' => $a[7], 
                                
'8' => $a[8], 
                                
'9' => $a[9], 
                                
'10' => $a[10],                                 
                                
'11' => $a[11], 
                                
'12' => $a[12], 
                                
'13' => $a[13], 
                                
'14' => $a[14
                                ); 
                                 
        
// Provide some output that it's doing stuff 
//        echo 'Updated: <b>' . $char['name'] . '</b> ' . $a[0] . '-' . $a[1] . '-' . $a[2] . '-' . $a[3] . '-' . $a[4] . '-' . $a[5] . '-' . $a[6] . '-' . $a[7] . '-' . $a[8] . '-' . $a[9] . '-' . $a[10] . '-' . $a[11] . '-' . $a[12] . '-' . $a[13] . '-' . $a[14] . '</br>'; 
                                 
        
$id++;                         
    } 
     
}  
/*
echo '</br>Inserting values into DB...</br>'; 

// Connect to the DB 
$db = mysql_connect($dbhost, $dbuser, $dbpasswd); 
$db_selected = mysql_select_db($dbname, $db); 

foreach ($member_data as $member) 

    $name = $member['name']; 

    $sql = "insert into ach_data2(name, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)
       VALUES ('$name', '$member[0]', '$member[1]', '$member[2]', '$member[3]', '$member[4]', '$member[5]', '$member[6]', '$member[7]', '$member[8]', '$member[9]', '$member[10]', '$member[11]', '$member[12]', '$member[13]', '$member[14]')"; 
    $result = mysql_query($sql); 
     
   if(!$result); 
       echo mysql_error() . "\n";     


echo 'Database update completed.'; 
*/

function find_category($xml

    foreach(
$xml->achievement as $ach) { 
        if(
$ach['id'] == 1658
            return 
$ach
    } 



function 
check_achievement($achievement$num) {
if(
$achievement ['dateCompleted'] != NULL)
        return 
1;
        else 
    if(
$achievement->criteria[$num]['date'] != NULL
        return 
1
    else 
        return 
0


?>

this one works without a problem but the ones in my earlier posts don't :'-(

talonos 07-06-2009 04:02 PM

ok i think i worked out my problem, seems that there are diffrent
Code:

</category>
    <category>

all over the xml file and i cant find a way to select the diffrent ones so for now ima scrp this script

talonos 07-13-2009 11:03 AM

ok if anyone wants to know i got my error resolved

find:
PHP Code:

function find_category($xml)  
{  
    foreach(
$xml->achievement as $ach) {  
        if(
$ach['id'] == 576)  
            return 
$ach;  
    }  


and replace with:
PHP Code:

function find_category($xml)  
{  
    foreach(
$xml->category as $cat)
    {
        foreach(
$cat->achievement as $ach)
        {  
            if(
$ach['id'] == 576)  
                return 
$ach;
        }
    }  




All times are GMT. The time now is 05:20 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0