tombruton Posted October 3, 2011 Share Posted October 3, 2011 I have a class in which I have a function called connection. I am now trying to call this function from another class, but it will not work. It works if I put the code in from the other function rather than calling it but that defeats the purpous. class locationbox { function location() { $databaseconnect = new databaseconnect(); $databaseconnect -> connection();{ $result = mysql_query("SELECT * FROM locations"); while($row = mysql_fetch_array($result)) // line that now gets the error, mysql_fetch_array() expects parameter 1 to be resource, boolean given //in { echo "<option>" . $row['location'] . "</option>"; } } }} Quote Link to comment https://forums.phpfreaks.com/topic/248356-calling-a-class-within-a-class/ Share on other sites More sharing options...
codefossa Posted October 3, 2011 Share Posted October 3, 2011 This should work. class locationbox { public $dbconnect; public function __construct() { $this -> $dbconnect = new databaseconnect(); $dbconnect -> connection(); } public function location() { $result = mysql_query("SELECT * FROM locations"); while ($row = mysql_fetch_array($result)) // line that now gets the error, mysql_fetch_array() expects parameter 1 to be resource, boolean given //in { echo "<option>" . $row['locations'] . "</option>"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/248356-calling-a-class-within-a-class/#findComment-1275385 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.