Mysql_fetch_field array to a regular PHP array?
Posted: Wed Jul 15, 2009 12:55 am
Hi everyone,
I know your all busy, so I'd like to thank you in advance and I'll try to keep everything short and concise.
Attempted To:
Convert and/or store the mysql_fetch_field array into a regular PHP array.
Error:
Notice: Undefined property: stdClass::$price
My Thoughts:
I'm new to OOP programming and I'm having a bit of trouble grabbing a set of data out of the database and making them stick inside a PHP array. I don't know whether its the mysql_fetch_field or the way I'm accessing the object. In either case, I'm sure its something silly. Its just i can't seem to get it working. The mysql_fetch_field gets the data and prints it , then it doesn't save it. It discards it. Perhaps its scope? Either way, here is the code. I have tried making it the most legible as possible. Ohhh and the setup function is missing since it connects to the db (has pass and such). Assume it works. (I made sure of it).
Code:
I know your all busy, so I'd like to thank you in advance and I'll try to keep everything short and concise.
Attempted To:
Convert and/or store the mysql_fetch_field array into a regular PHP array.
Error:
Notice: Undefined property: stdClass::$price
My Thoughts:
I'm new to OOP programming and I'm having a bit of trouble grabbing a set of data out of the database and making them stick inside a PHP array. I don't know whether its the mysql_fetch_field or the way I'm accessing the object. In either case, I'm sure its something silly. Its just i can't seem to get it working. The mysql_fetch_field gets the data and prints it , then it doesn't save it. It discards it. Perhaps its scope? Either way, here is the code. I have tried making it the most legible as possible. Ohhh and the setup function is missing since it connects to the db (has pass and such). Assume it works. (I made sure of it).
Code:
Code: Select all
class Billable{
[color=#40FF00]// Private Variable[/color]
private $con;
private $results;
[color=#40FF00]// resuable ones[/color]
public $row;
public $row2 = array();
[color=#40FF00]//Sets the Object Type[/color]
function type($type){
$query='SELECT * FROM '.$type;
$this->results=mysql_query($query);
$row2 = mysql_fetch_field(mysql_query($query));
while (mysql_fetch_array($this->results)){
echo $row2->price; // [color=#FF0000]This is where the problem is here[/color]
}
return ($this->results);
}
function getPrice($index){
[color=#0000FF] //I can't get prices, if I can't get the row2 array[/color]
return ($index);
}
}
echo "<br>Takeup<br>";
$TakeUp = new Billable();
$TakeUp->setup(); //Does database connection ... don't worry about it. It works
$TakeUp->type("TakeUp");
echo $TakeUp->getPrice(0);