[UPHPU] SQL field as prefix for all fields

Craig Jackson CJackson at cirris.com
Mon Jan 28 16:03:49 MST 2008


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?



More information about the UPHPU mailing list