Re: Retreive data from multiple columns by ['tablename.colname']

From: Date: Thu, 16 Oct 2003 16:21:33 +0000
Subject: Re: Retreive data from multiple columns by ['tablename.colname']
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31082@lists.php.net to get a copy of this message
Erik Björling wrote:
Hi, I use a query with multiple tables: SELECT * FROM cases,status,prio where cases.statusid=status.id && ..... I retreive the data into my variable $line like this. while ($line = mysql_fetch_array($result)) {..... How can I retreive data from $line without using the index value as integers for example $line[13] I would like to write $line['cases.id'] to retreive 'id' data from the table 'cases' in a SQL-manner. But I get an error message regarding unknown index 'cases.id'.
Take a look at $line and you'll see the values are already there. $line['id'], etc. Use print_r() on $line to see it's contents.
Is there an easy solution to this? Is there another sign then '.' or should I use other names for my 'id'-columns such as c_id, s_id.... etc.?
Yes, this is recommended. Otherwise the "id" column from one table will overwrite the value from another table when it's all put into $line. Use an alias and remember that the keys do not include the table name, only the column name: $line['id'] instead of $line['table1.id']. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.db (#31082) next »