From: Josh Grams Date: Sat, 22 Aug 2009 17:29:23 +0000 (-0400) Subject: * db.php (db_get_assoc, db_get_assocs): new functions to ease use of new template... X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=3faf64c6a1e0cbd4f880da951775c41fb8a6f0ab * db.php (db_get_assoc, db_get_assocs): new functions to ease use of new template code. --- diff --git a/db.php b/db.php index 4a58db8..f39d5e0 100644 --- a/db.php +++ b/db.php @@ -166,6 +166,22 @@ function db_get_rows($table, $columns, $where = '') { return $rows; } +# like db_get_rows, but return array of hashes. +function db_get_assocs($table, $columns, $where = '') { + $args = func_get_args(); + $args = array_slice($args, 3); + $result = db_send_get($table, $columns, $where, $args); + + $rows = array(); + while($row = mysql_fetch_assoc($result)) { + $rows[] = $row; + } + + mysql_free_result($result); + + return $rows; +} + function db_get_column($table, $columns, $where = '') { $args = func_get_args(); $args = array_slice($args, 3); @@ -193,6 +209,19 @@ function db_get_row($table, $columns, $where = '') { return $row; } +# like db_get_row, but return a hash. +function db_get_assoc($table, $columns, $where = '') { + $args = func_get_args(); + $args = array_slice($args, 3); + $result = db_send_get($table, $columns, $where, $args); + + $row = mysql_fetch_assoc($result); + + mysql_free_result($result); + + return $row; +} + function db_get_value($table, $columns, $where = '') { $args = func_get_args(); $args = array_slice($args, 3);