It appears that the 'table.field' dot notation is not preserved by
php's mysql library.
I can create some join 'SELECT a.id, b.id FROM table1 AS a,
table2 AS b' but when I try to refer to the fields as 'a.id' and
'b.id' the reference fails because the table aliases have been
discarded from the dataset as managed by php. 'a.id' has become
merely 'id', and 'b.id' no longer has a fieldname -- the only way to
refer to it is by the numeric index.
Or am I doing something wrong (I hope so!)? I can't find any mention
of this problem in any docs, so it's totally possible that I'm goofing
something up without realising it. If it's a real problem, it's an
annoying one because it means we must (a) name all fields uniquely
even across tables, (b) avoid doing joins, or (c) get used to using
the numeric indexes to the fields instead of their names.
My test program:
$link = mysql_connect( $_SERVER['HTTP_HOST'] ) ;
if ( empty( $link ) ) die( 'Cannot connect to the server' ) ;
$attached = mysql_select_db( 'dbase' ) ;
if ( ! $attached ) die ( 'Cannot connect to the database' ) ;
$q = 'select i.id, s.id from table_issues as i, table_scopes as s
where i.id=3 and i.scope=s.id' ;
$dset = mysql_query( $q, $link ) ;
if ( $dset )
{
$rec = mysql_fetch_array( $dset ) ;
foreach ( $rec as $k => $v )
echo $k . ' is ' . $v . '<br>' ;
}
yields this result:
0 is 3
id is 129
1 is 129
Thanks in advance for any insights.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)