RE: [PHP] MySQL query/PHP logic?
| From: | Jennifer Goodie | Date: | Tue, 29 Jul 2003 21:31:02 +0000 |
| Subject: | RE: [PHP] MySQL query/PHP logic? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-157440@lists.php.net to get a copy of this message | ||
> select * from main
> left join fof on main.id = fof.id
> left join pub on main.id = pub.id
> left join gov on main.id = gov.id
> left join med on main.id = med.id
> left join ngo on main.id = ngo.id
> left join own on main.id = own.id
> left join sup on main.id = sup.id
[snip]
> BUT, although it seems to be "joining" the tables correctly AND only
> returning the ones with the correct date criteria, it does NOT return
> the "id" or the "information_sent" fields correctly ( due to duplication
> in the result )
>
> Can this be done in one query without sub-selects, or should it
> be broken up
> (in which case I would still need help with the logic and to minimize the
> amount of queries inside loops)
>
Instead of select * list out the fields you want to select and alias the
duplicates, for example
select fof.id as fof_id, pub.id as pub_id, gov.id as gov_id etc.
Then when you do you mysql_fetch_array the indexes will be the aliases you
gave the columns so nothing will get overwritten.