PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to write a function that queries a database based on using a MySQL entry ID as its argument and then using the contents of the resulting array of that query in another function.
Here is the code I have... I'm trying to figure out how to make it so I can use the $results variable from the db_edit function to create separate variables for each array row in the get_info function.
Any advice would be GREATLY appreciated... THanks
<?php
class basics{
public function db_edit($object_id){
require('connection.php');
$query = "select * from table where id = '".$object_id"' limit 0, 1";
$results = $db->query($query);
$db->disconnect();
}
public function get_info($category, $object_id){
require('connection.php');
$info_query = new basics();
$info_query->db_edit(4);
$row = &$results->fetchrow(MDB2_FETCHMODE_ASSOC);
$object_title = $row['object_title_field'];
$db->disconnect();
}
}
?>
Last edited by Benjamin on Fri Jan 14, 2011 9:16 pm, edited 1 time in total.
Reason:Added [syntax=php] tags.
I tried return but it didn't work... it resulted in the following error:
Fatal error: Call to a member function fetchrow() on a non-object in basics.inc
The whole point of grouping functions into a class is so that they can share data. Passing thru a parameter is the "wrong" way. Using a class member is the "correct" way.