You are here: Re: Looping through 2 query results « PHP SQL « IT news, forums, messages
Re: Looping through 2 query results

Posted by Captain Paralytic on 02/08/07 10:00

On 7 Feb, 21:58, "Kenoli" <kenol...@gmail.com> wrote:
> Suppose I have results from 2 queries each to a different table:
>
> $result1 = (mysql_query($query1);
>
> and
>
> $result2 = (mysql_query($query2);
>
> And I want to loop through both of them in order to put some values
> from each in a table.
>
> With one, I would do:
>
> while ($row1 = mysql_fetch_array ($result1)) { etc.
>
> <td><?=$row1['column1']?></td> etc.
>
> Suppose I want the next cell to be:
>
> <td><?=$row2['column1']?></td> //associated with $result2
>
> How do I construct the "while" conditional to loop through both
> queries????
>
> The results are linked by a common column (person_id).
>
> Thanks,
>
> --Kenoili
>
> --Kenoli

If the results are linked by a common column then query using a JOIN
between the tables thus:

SELECT *
FROM table1
JOIN table2 USING(person_id)
WHERE .....

Then all your results are in single rows based on person_id

 

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

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