Jump to content

[SOLVED] class method


corillo181

Recommended Posts

hey I want to know how I can use a fetch_array to do something like this

 

<?php

class artistpro{
var $id;
var $db;

function artistpro($id){
	$this->id = $id;
	$this->db = new DB();
}

function body(){
	$query = "SELECT * FROM tra_artist WHERE artist_id='{$this->id}'";
	$result = $this->db->query($query);
	$aray = $this->db->fetch_array($result);
		}

function name(){
return  $aray['name'];
}

function age(){	
        return $aray['age'];
}

function genre(){
 return $aray['genre'];
}
}
?>

 

the only problem is that this doesn't work with the array, does anyone knows how i could do it?

Link to comment
https://forums.phpfreaks.com/topic/70437-solved-class-method/
Share on other sites

i tried doing some test using that way and this are the results

<?php

class artistpro{
var $id;
var $db;
var $aray;

function artistpro($id){
	$this->id = $id;
	$this->db = new DB();
}

function body(){
	$query = "SELECT * FROM tra_artist WHERE artist_id='{$this->id}'";
	$result = $this->db->query($query);
	$this->aray = $this->db->fetch_array($result);

var_dump($this->aray['name']);// = artist name
var_dump($this->aray);// all values in array			
		}

function name(){
var_dump($this->aray['name']);// = NULL
}

function age(){	
var_dump($this->aray['name']);// = NULL
}

function genre(){
var_dump($this->aray['genre']);// = NULL
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/70437-solved-class-method/#findComment-353884
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.