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']; } } } ?> Quote Link to comment 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']; } } } ?> Quote Link to comment 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.