omar-do Posted August 10, 2011 Share Posted August 10, 2011 i have this code how can i call $result in the while looping who's in other function ? <?php class project0 { public function mysql_connection() { $host = 'localhost'; $user = 'root'; $password = ''; $db = 'om'; $dbtbl = 'omtbl'; $connetion = mysql_connect($host,$user,$password); $select = mysql_select_db($db); $result = mysql_query("SELECT * FROM $dbtbl"); } public function show_my_users(){ while ($row = mysql_fetch_array(HOW CAN I CALL $result HERE ?)) { print $row['id']; } } } ?> Link to comment https://forums.phpfreaks.com/topic/244442-opp-help/ Share on other sites More sharing options...
The Little Guy Posted August 10, 2011 Share Posted August 10, 2011 Like this: <?php class project0 { private $result; public function mysql_connection() { $host = 'localhost'; $user = 'root'; $password = ''; $db = 'om'; $dbtbl = 'omtbl'; $connetion = mysql_connect($host,$user,$password); $select = mysql_select_db($db); $this->result = mysql_query("SELECT * FROM $dbtbl"); } public function show_my_users(){ while ($row = mysql_fetch_array($this->result)) { print $row['id']; } } } ?> Link to comment https://forums.phpfreaks.com/topic/244442-opp-help/#findComment-1255605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.