The answer might be write two functions! However, maybe a little knowledge that I do not have will help avoid a heck of a lot of re-factoring or database usage.
I have a function with the very common syntax of:
while($row = $db->sql_fetchrow($result)) {
// do some stuff
}
Most of the time, the $row will be a mysql object with zero, one or more rows therein. Simple.
However, it would be very handy if I could also utilise a three dimensional PHP array (previously built to be a bunch of "rows" with three key & value pairs) without handling them differently.
The question I have is "What do I need to do to a 3D array to "convert" it to a mysql object that will work without change in the above example"?
There isn't a way to convert into a mysql object without writing to a tmp table and reading it back in. The following will deal with either sql statement or array turning up which then negates the need to convert as the question asked.
$all_rows = $notify->notification_sql(); // This either returns an SQL statement ready to run OR a set of rows in an array
if (!is_array($all_rows)) { // If it's not an array, run the SQL query and put it into an array of rows
$result = $db->sql_query($all_rows);
$all_rows = array();
while($row = mysql_fetch_array($result)) {
$all_rows[] = $row;
}
}
foreach...