...

View Full Version : class function, not able to see other function



udjamaflip
12-17-2008, 04:25 PM
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?



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

kieran491
12-17-2008, 04:32 PM
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()"

Fou-Lu
12-17-2008, 11:15 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum