postgresql - PHP result from a query with alias -


when want data sql query on php system, write like

<?php echo $sqlresult['fieldfromresult'];?> 

i wondering if can put alias directely on 'fieldfromresult'.

example:

select tb1.*, tb2.*, tb3.* tableone tb1, tabletwo tb2, tablethree tb3  id = 1 , tb1.idcolumn=tb2.idcolumn , tb1.idcolumn=tb3.idcolumn 

you see, should easy if specify want every table (one, 2 or three), want all. name of of these columns same. example: tableone , tablethree has column named "description".

what want in php a

<?php echo $sqlresult['tb1.description'];?> 

if use <?php echo $sqlresult['description'];?> doesn't work.

is there way make without specify columns want on query?

in order output contain table name column name you'd need write own output class/function this, referencing table schema/meta data , creating own array keys this.

or

you simpy name them assosciation as such that:

select tb1.description t1_description, tb2.description t2_description ... etc  

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -