Jump to content

opp help !


omar-do

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.