I concur with Jason, but if restructuring is out of the question, just
rearrange your queries like this:

$query = "SELECT Name, Address FROM users";
$result = mysql_query($query);
while($details = mysql_fetch_array($result)){
    echo "Name: $details[Name]";
    echo "Address: $details[Address]";
$query2 = "SELECT EmailAddress From Members";
$result2 = mysql_query($query2);
while($details = mysql_fetch_array($result2)){
    echo "Email: $Email[EmailAddress]";

The results won't come out at the same time, but you could use some
logic to combine the results into an array by a common factor. Just
remember that you can only work with one mysql result per connection at
a time. You *may* (untested!) be able to accomplish what you want to do
with two separate connections, but again, this is seriously overkill. :)

I'd definitely recommend restructuring your talbes as Jason suggested.
-- Josh

-----Original Message-----
From: Jason Wong [mailto:phplist@;gremlins.com.hk] 
Sent: Wednesday, November 06, 2002 5:24 AM
Subject: Re: [PHP-DB] mysql_fetch_array() question

On Tuesday 05 November 2002 05:47, Graeme McLaren wrote:
> Hi, Anyone know how I can use two mysql_fetch_array() functions
> to the code below?  I've tried a few different ways but I keep getting
> Resource ID #4.  I need to do this to retrieve an email address from
> table and retrieve details from another.
> Cheers for any tips - I'm stumped with this one,
> Graeme :)
> $query = "SELECT Name, Address FROM users";
> $query2 = "SELECT EmailAddress From Members";
> $result = mysql_query($query);
> $result2 = mysql_query($query2);
> while($details = mysql_fetch_array($result) and $Email =
> mysql_fetch_array($result2))
> {
>     echo "Name: $details[Name]";
>     echo "Address: $details[Address]";
>     echo "Email: $Email[EmailAddress]";
> }

Unless I've missed something you're going about this the wrong way. For
you want to do, you should (in general) be able to accomplish it using
just a 
single query.

What fields do the tables 'users' and 'Members' contain? There should be
field there (like eg. userid) which links the two together. If there
one then you should seriously restructure your tables so that there is

Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

Cats are smarter than dogs.  You can't make eight cats pull a sled
the snow.

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to