mysql php table join
I am probably doing something stupid but have been working on this for a
day and can't seem to find error.
I have a join of several tables. When I print out the results using
print_r(mysql_fetch_array($res), I see a value for the field I want.
However, when I try to echo this out or otherwise get access to it, it
seems to be empty. Can anyone spot what I am doing wrong? Thanks in
advance as this is driving me crazy.
tables (some fields omitted)
members
id|username|password|datetime|email
membercontact
id|memberid|contactid
php
$sql = "SELEcT m.*,mc.*,mc.contactid as mccon
from `members` m
LEFT JOIN `membercontact` mc
on m.id = mc.memberid
WHERE m.id = '147'"
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)) {
echo $row['contactid'];
echo $row['mccon']
}
output: nothing . I've also tried other ways to access the contactid
field. Other fields do print such as $row['password']
However when I use print_r on the results I can see following:
Array ( [0] => v [username] => v [1] => pass [password] => pass [2] => 147
[id] => 147 [3] => 2013-09-05 12:08:03 [datetime] => 2013-09-05 12:08:03
[4] => vz@aol.com [email] => v@aol.com [19] => 933 [contactid] => 933 [20]
=> 147 [memberid] => 147 [24] => 933 [contactid] => 933 )
The only thing weird I notice is that some fields are repeated more than
once, notably contactid though I cannot say why. (The reason for the skips
in numbers is there are a lot of other extraneous fields omitted.)
No comments:
Post a Comment