You are here: Re: Syntax for ambigous fields in a query with joins? « All PHP « IT news, forums, messages
Re: Syntax for ambigous fields in a query with joins?

Posted by Jim Michaels on 03/02/06 20:13

<plaidthermos@hotmail.com> wrote in message
news:1140637462.845949.144170@f14g2000cwb.googlegroups.com...
>i found a topic on this question posted a couple years ago, but it
> didn't really help me. my problem is the same as the original
> poster's, that is, i have a query that returns multiple fields with the
> same name. i need to access these in php via mysql_fetch_assoc, like
> $row["field_name"]. the only response suggested using aliases in the
> select, but that is not really practical, as i am selecting * from all
> tables, and writing
>
> select t1.field1 as t1f1, t2.field1 as t2f1, t1.field2 as t1f2,
> t2.field2 as t2f2, t1.field3 as t1f3 ... t1.field100 as on and on and
> on
>
> is hardly desirable. does anyone know a way to access these fields
> from php without specifying aliases in the sql select statement? i
> don't really want to use field indices, as the table structure could
> change and just because table.field1 is the first field in the table
> today doesn't mean it always will be in that same position.
>
> any solutions?
>
> thanks,
> -k
>

straight from the manual on mysql_fetch_array:
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
mysql_free_result($result);
?>

this should work fine with your problem.

 

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

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