note 38560 added to function.in-array
| From: | eth at etheriushp dot dyndns dot org | Date: | Sat, 27 Dec 2003 12:06:40 +0000 |
| Subject: | note 38560 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62551@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+38560
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38560&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38560&report=yes
Search -- http://master.php.net/manage/user-notes.php