SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A function returning newsitems.

    Hello!

    I've done this function:

    PHP Code:
    function getNewsArray($fields="*",$numberOfNews 10
            {
                
    $sql "SELECT $fields FROM $this->getTable() ORDER BY $this->orderField DESC LIMIT $numberOfNews";
                
    $result mysql_query($sql) or die(mysql_error());
                return 
    $result;
            } 
    I get this message:


    Notice: Undefined property: getTable in c:\easyphp\www\developersclub\classes\class_news.php on line 15


    line 15 is the $sql = ...
    and I've got another function looking like this:

    PHP Code:
    function getTable() 
            {
                return 
    $this->table;    
            } 
    What's wrong? Can I make an sql string like I've done it in the getNewsArray function?

    Thanks in advance!

    Martin Lundberg
    Sweden

  2. #2
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whops! Sorry,

    I don't know if this is a good way of dealing with the problem but i made it work by writing it like this:
    PHP Code:
    $sql "SELECT ".$fields." FROM ".$this->getTable()." ORDER BY ".$this->orderField." DESC LIMIT ".$numberOfNews
    any better ideas would be appreciated

    thanks again!

    Martin Lundberg
    Sweden


Bookmarks

Posting Permissions

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