note 38560 deleted from function.in-array by nlopess
| From: | nlopess@php.net | Date: | Sat, 27 Dec 2003 12:08:11 +0000 |
| Subject: | note 38560 deleted from function.in-array by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62552@lists.php.net to get a copy of this message | ||
Note Submitter: eth@etheriushp.dyndns.org
----
You pass a query and the result of a query to this function and it returns an array formatted
properly using the field names from the database:
For Example:
$query = "SELECT id,title FROM users";
$result = (The Query result)
you run:
$ret = ParseQuery($query,$result)
it returns:
$ret["id"]=(whatever)
$ret["title"]=(whatever)
It also works with "SELECT *" in which case it automatically retrieves the field list from
the database
function ParseQuery($query,$arr)
{
$tmp = explode(" ",$query);
if ( $tmp[1] == "*" )
{
$q = "DESCRIBE threads";
$dbq = mysql_query($q);
if ( !$dbq )
return false;
while ( $r[] = mysql_fetch_row($dbq) );
foreach ( $r as $r2 )
{
$fields[$r2[0]] = $r2[0];
}
} else {
$fields_tmp = explode(",",$tmp[1]);
foreach ( $fields_tmp as $r )
$fields[$r]=$r;
}
$i=0;
foreach ( $fields as $r )
{
$fields[$r] = $arr[$i];
$i++;
}
return $fields;
}