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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.