Jump to content

Prefixed field names


nfvindaloo

Recommended Posts

Hi

I need to retrieve columns from the same table twice, using aliased names in the query.

When php retrieves a record i would expect ambiguous column names to be prefixed with the table name; ie: table.column, but mysql_fetch_assoc() seems to overwrite the ambigous columns so i only get the data from the last alias of the table.

There must be a way around this, is there a config option / runtime setting?

Thanks,
Nic
Link to comment
Share on other sites

Well, there isn't a way to do this in MySQL -- if you ask for 2 fields with the same name, you'll get back 2 fields with the same name, and the 2nd one will overwrite the 1st in the hash. Of course, if you get back an array of columns, this isn't a problem. If you want table.column, ask for table.column. The DB doesn't handle this for you. However, it is possible that PHP has a wrapper for this that I'm not aware of.
Link to comment
Share on other sites

PHP doesn't have anything special for this. Use mysql_fetch_row() and get the results numerically. For instance:

SELECT col1, col2, col3, col1 FROM table
...
$row = mysql_fetch_row()
...
$col1_firsttime = $row[0];
$col2 = $row[1];
$col3 = $row[2];
$col1_secondtime = $row[3];
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.