MattF wrote:Smartys wrote:You would have to use $db->fetch_assoc($result) or $db->fetch_row($result) to get at the actual data
So I assume that would mean it's getting back to multiple database lookups, then? Must admit, until I've started looking at this idea, I hadn't realised just quite how convoluted it is. Php has more features than you can shake a stick at, but it definitely doesn't do anything the easy way.
No, it's not very complicated at all and doesn't involve any more database lookups. It sounds like I need to explain the way things work
When you do $db->query, it returns a resource. That resource can then be given to certain functions (in PunBB's abstraction layer, $db->fetch_assoc and $db->fetch_row are 2 examples) which will allow you to traverse the data.
Your code using $db->fetch_assoc would look something like
$result = $db->query("SELECT id, username FROM ".$db->prefix."users") or error('Could not get user list', __FILE__, __LINE__, $db->error());
$users = array();
while($user = $db->fetch_assoc($result))
$users[$user['id']] = $user['username'];
Your code using $db->fetch_row would look something like
$result = $db->query("SELECT id, username FROM ".$db->prefix."users") or error('Could not get user list', __FILE__, __LINE__, $db->error());
$users = array();
while(list($id, $username) = $db->fetch_row($result))
$users[$id] = $username;