You are here: Re: resultset and two tables in sql query « All PHP « IT news, forums, messages
Re: resultset and two tables in sql query

Posted by J.O. Aho on 12/03/07 21:36

bender wrote:
> Is possible to read variable using table.fieldName like in example?
>
> example query: SELECT table1.*, table2.* FROM teble1, table2 WHERE
> table1.id = table2.id;

SELECT * FROM teble1, table2 WHERE table1.id = table2.id;

If you want only a limited number of columns

SELECT table1.col1,table1.col2,table2.col2, table2.col5 FROM teble1, table2
WHERE table1.id = table2.id;


> $rs = $this->dbc->query($sql->createSelect());
> while($row=$rs->fetch_array()){
> $retVal[]=$row[table.fieldName] // doesnt work, $row[fieldName]
> //does work
> }

In PHP you will only get the column name as the array cell key name when you
use fetch_array, so $row['fieldName'] will work, you can get trouble if you
have columns with the same name, I suggest you in those cases use AS in your
query to rename those

SELECT table1.col1,table1.col2 AS col2-1,table2.col2 AS col2-2, table2.col5
FROM teble1, table2 WHERE table1.id = table2.id;

This way you won't have trouble with cell keys having hte same name.


--

//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация