PHP Mysql echoing data in one column from multiple rows -
my mysql table looks this:
and want retrieve data column 'host' uid equal twenty.
i have code connect database , return row when uid equal twenty
db.php:
public function query($sql, $params = array()){ $this->_error = false; if($this->_query = $this->_pdo->prepare($sql)){ $x = 1; if(count($params)){ foreach($params $param){ $this->_query->bindvalue($x, $param); $x++; } } if($this->_query->execute()){ $this->_results = $this->_query->fetchall(pdo::fetch_obj); $this->_count = $this->_query->rowcount(); } else { $this->_error = true; } } return $this; } public function results(){ return $this->_results; }
server.php:
public static function get($uid){ $_db = db::getinstance(); $data = $_db->get('servers', array('uid', '=', $uid)); return $data->results(); }
curl.php:
$a = server::get('20'); var_dump($a);
the var_dump on return gives following:
array(2) { [0]=> object(stdclass)#5 (4) { ["sid"]=> string(2) "13" ["host"]=> string(12) "example.home" ["port"]=> string(4) "8081" ["uid"]=> string(2) "20" } [1]=> object(stdclass)#6 (4) { ["sid"]=> string(3) "153" ["host"]=> string(15) "stream.as.ag.ca" ["port"]=> string(5) "23434" ["uid"]=> string(2) "20" } }
note: if question has been answered somewhere else, link provided couldn't find answer.
i think should able pull each host this.
foreach($a $row) { echo $row->host; }
Comments
Post a Comment