我正在尝试从多个表中获取数据"具有相同的列名"但它并没有给我在drupal中所需的结果。 这是我的代码。
$result = db_query ( "select table1.symbol, table2.symbol, table1.price_sales, table2.price_sales from {table1, table2} where table1.uid = table2.uid" );
while ( $obj = $result->fetch () ) {
echo ($obj->table1.symbol); // it doesn't return the results
echo ($obj->table2.symbol);
}
答案 0 :(得分:0)
fetch()
不是 DatabaseStatementInterface
上Dupral 7.x
的方法。试试fetchAllAssoc()
或fetchAllKeyed()
答案 1 :(得分:0)
您应该能够在运行查询时更改任何列的名称:
$result = db_query ( "select table1.symbol as second_symbol, table2.symbol, table1.price_sales, table2.price_sales from {table1, table2} where table1.uid = table2.uid" );
while ( $obj = $result->fetch () ) {
echo ($obj->table1.second_symbol);
echo ($obj->table2.symbol);
}