nfvindaloo Posted March 17, 2006 Share Posted March 17, 2006 HiI 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 Quote Link to comment https://forums.phpfreaks.com/topic/5198-prefixed-field-names/ Share on other sites More sharing options...
fenway Posted March 19, 2006 Share Posted March 19, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5198-prefixed-field-names/#findComment-18849 Share on other sites More sharing options...
wickning1 Posted March 20, 2006 Share Posted March 20, 2006 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]; Quote Link to comment https://forums.phpfreaks.com/topic/5198-prefixed-field-names/#findComment-18974 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.