|
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
[Back to original message]
|