Example :
Code: Select all
function fetch_assoc($field)
{
while($row=mysql_fetch_assoc($this->sql))
{
$field_data[] = $row[$field];
}
return $field_data;
}The problem lies within the fact that if I send it a field once to query and return an array of rows back from, it works fine. But, when I send it another field, it returns a blank array.
Example
Code: Select all
include('myclass.php');
$a = new MyClass;
$a->connect();
$a->select_db('whatever');
$a->query('select date,time from mytable');
$first_array = $a->fetch_assoc('date');
$second_array = $a->fetch_assoc('time');i understand that when mysql_fetch_assoc is called, it queries the sql statement, returns what arrays are called, and then frees the query. But, what if you are wanting to do what I am trying to do?
Obviously an easy work around is to just send an array of fields that are to be populated into the $row array
example :
Code: Select all
$my_fields = $a->fetch_assoc('field','field2');Another solution would be to just write the function to where it fetchs and all fields, builds arrays for all fields, and then returns only the fields that are set in the $a->fetch_assoc($field) call...
Again, I am just being a hardass about this and basically am just wondering if there is a solution to do it the way I had originally intended. Thanks