0

I am trying to use a returned string from my function 'get_setting' inside my class name 'settings'. I wanna use the returned string for the variable 'top_banner'. When I try using the '$this' variable to access the function, it does not work.

class settings{

 function get_setting($name, $return="value"){
    $query = mysql_query("SELECT * FROM website_settings WHERE name='".$name."'");
    $row = mysql_fetch_array($query);
    if($row['active'] == false){//This is turned off
        return "disabled";
    }else{//this setting is active
        return $row['value'];
    }

}
    //Values
public $top_banner = $this->get_setting("top_banner");
}
  • Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://jayblanchard.net/demystifying_php_pdo.html). Some *simple* error checking would reveal that you're calling a function that is not defined. – Jay Blanchard Apr 22 '15 at 15:44

1 Answers1

0

try this:

class settings{

 function get_settings($name, $return="value"){
    $query = mysql_query("SELECT * FROM website_settings WHERE name='".$name."'");
    $row = mysql_fetch_array($query);
    if($row['active'] == false){//This is turned off
        return "disabled";
    }else{//this setting is active
        return $row['value'];
    }

   }
}
  //Values
$my_settings = new settings();
$top_banner = $my_settings->get_settings("top_banner");
Ari Djemana
  • 1,229
  • 12
  • 12