[UPHPU] SQL field as prefix for all fields
Craig Jackson
CJackson at cirris.com
Mon Jan 28 16:13:51 MST 2008
I really should have reviewed this before I sent it. I forgot one piece of importance. The first line needs to have the parameter MYSQL_ASSOC sent with mysql_fetch_array. Plus, you would need to do more tweaking to get this to work for if you were returning multiple rows, but I think I got my idea across.
$a = mysql_fetch_array(mysql_query("SELECT * FROM containers"), MYSQL_ASSOC);
Craig Jackson
-----Original Message-----
From: uphpu-bounces at uphpu.org [mailto:uphpu-bounces at uphpu.org]On Behalf
Of Craig Jackson
Sent: Monday, January 28, 2008 4:04 PM
To: Wade Preston Shearer; UPHPU Discuss
Subject: RE: [UPHPU] SQL field as prefix for all fields
Off the top of my head, you cannot do anything like this in MySQL (the only database I have a solid knowledge of). But, I would imagine you could maybe do something like this in PHP. Lets say you are returning one row, and the prefix is 5 characters long.
$a = mysql_fetch_array(mysql_query("SELECT * FROM table"));
foreach ($a as $key => $value) {
$str = substr($key, 5);
$new_a[$str] = $value;
}
Hopefully, this would help in some way.
Craig Jackson
-----Original Message-----
From: uphpu-bounces at uphpu.org [mailto:uphpu-bounces at uphpu.org]On Behalf
Of Wade Preston Shearer
Sent: Monday, January 28, 2008 3:51 PM
To: UPHPU Discuss
Subject: [UPHPU] SQL field as prefix for all fields
The AS option in an SQL command allows you to rename a field, like this:
select username as user, password as secretcode
Is it possible to rename all of the fields that you pull at once?
Here's what I want to do:
I have a table of fields that are all named with the same prefix. I
want to rename them as they are pulled from the DB with a different
prefix. Is that possible?
_______________________________________________
UPHPU mailing list
UPHPU at uphpu.org
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net
More information about the UPHPU
mailing list