Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2008
    Posts
    235
    Thanks
    6
    Thanked 21 Times in 20 Posts

    class function, not able to see other function

    Hi guys, I have the class below and have this error:


    Fatal error: Call to undefined function: getattachments()


    If I note out the line using the function the page loads but obviously the function doesn't work thats using it, is there something I need to do to use a function within the same class as the function calling it?

    PHP Code:
    class contentDisplay {
        function 
    getArticle($id 'first'$catId)
        {
            if (
    $id 'first')
            {
                
    $this->sql 'SELECT * FROM jos_content WHERE catID='.$catId.' ORDER BY ordering';
            }
            else
            {
                
    $this->sql 'SELECT * FROM jos_content WHERE catID='.$catId.' AND id='.$id.' LIMIT 1';
            }
            
            
    $this->query mysql_query($this->sql);
            
    $i 0;
            
            while (
    $row mysql_fetch_array($this->query))
            {
                if (
    $i 0)
                {
                    
    $this->content['title'] = $row['title'];
                    
    $this->content['introtext'] = $row['introtext'];
                    
    $this->content['fulltext'] = $row['fulltext'];
                    
                    
    $cat getCategoryInfo($id);
                    
    $this->content['subnav'] = '<li><a href="'.$cat['alias'].'/'.$row['id'].'-'.$row['alias'].'.html" title="'.$cat['title'].'">'.$cat['title'].'</a></li>';
                }
                else
                {
                    
    $cat getCategoryInfo($id);
                    
    $this->content['subnav'] = '<li><a href="'.$cat['alias'].'/'.$row['id'].'-'.$row['alias'].'.html" title="'.$cat['title'].'">'.$cat['title'].'</a></li>';
                }
                
    $i++;
            }
            
            
    $this->content['image'] = getAttachments($row['id']);
            
            return 
    $this->content;
            
        }
        
        function 
    getCategoryInfo($id)
        {
            
    $this->sql 'SELECT * FROM jos_categories WHERE id='.$id.' LIMIT 1';
            
    $this->query mysql_query($this->sql);
            
    $row mysql_fetch_array($this->query);
            
            
    $this->content['title'] = $row['title'];
            
    $this->content['alias'] = $row['alias'];
            
            return 
    $this->content;
        }
        
        function 
    getAttachments($id$limit 1)
        {
            
    $this->sql 'SELECT * FROM jos_attachments WHERE article_id='.$row['id'].' AND file_type LIKE "%image%" LIMIT '$limit;
            
    $this->query mysql_query($this->sql) or die ('failed: 'mysql_error());
            
    $row mysql_fetch_array($this->query);
            
            if (
    mysql_num_rows($this->query))
            {
                
    $this->content['image'] = '<img src="'.$row['url'].'" alt="'.$row['display_filename'].'" title="'.$row['display_filename'].'" width="330px" />';
            }
            else
            {
                
    $this->content['image'] = 'No Image available.';
            }
            
            return 
    $this->content['image'];
        }

    Thanks,

    Andy
    Andrew Sharman
    Web designer, developer and programmer.

    If you found my post helpful, why not give thanks! :)

  • #2
    New Coder
    Join Date
    Jun 2008
    Posts
    76
    Thanks
    6
    Thanked 6 Times in 6 Posts
    I just tryed your code it seems to work for me i get no error about it been unable to find a the function "getAttachments()"

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    It won't work no.
    Unlike other OO languages, PHP doesn't use variable masking. This means that any object access requires the use of $this->x[()] instead of just the x[()] like other languages handle.
    Use $this->getAttachments() and it will work.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •