Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old March 28th, 2003, 03:22 AM
cherylw cherylw is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Dougalsville, GA USA
Posts: 10 cherylw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to cherylw
help with join mysql - php

Hi, I have two tables and I need to get the
information for both to display a picture and
member data.

-----
members
memmberId (primary key), fname
memberImg
ID (primary key), filename,memID

This query
SELECT memberImg.filename,members.fname
FROM memberImg,members
where memberImg.ID = 2;

returns 60 records, I am trying to get 1 where
the ID = 2 or myVar.
the memID filed gets updated when the user
adds the picture. The memeberImg.memID matches the members.memberID.

Can someone please help me with this join.

Thanks,
~cherylw

Reply With Quote
  #2  
Old March 28th, 2003, 05:08 AM
NetproHosting NetproHosting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apex, NC, USA
Posts: 31 NetproHosting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to NetproHosting
RE: help with join mysql - php

Hi Cheryl,

Looks like your query is not tying the two tables together based on the relationship between members.memberID and memberImg.memID.

Try:

SELECT memberImg.filename,members.fname
FROM memberImg,members
where memberImg.ID = 2 AND
members.memberId = memberImg.memID;

Hope this helps,

Reply With Quote
  #3  
Old March 28th, 2003, 10:49 AM
cherylw cherylw is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Dougalsville, GA USA
Posts: 10 cherylw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to cherylw
RE: help with join mysql - php

thanks for your reply on this I am really desperate once again. I am not getting any data with that query, but it looks like the right approach. Let me explain. I need to match the memberImg.memId with members.memberID where
memberImg.memID = '$currID'
here's what I tried...

$sql_result = mysql_query("SELECT memberImg.filename,memberImg.ID,*
FROM memberImg,members where memberImg.memID = '$currID' AND members.memberId = memberImg.memID;", $db);


thanks and I really could use the help I am supposed to have this directory by the morning est.

~cherylw

Reply With Quote
  #4  
Old March 28th, 2003, 11:08 AM
cherylw cherylw is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Dougalsville, GA USA
Posts: 10 cherylw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to cherylw
RE: help with join mysql - php

update.. this works now... after I my last post it made more sense to me;

$sql_result = mysql_query("SELECT *, memberImg.filename,memberImg.ID
FROM members,memberImg where memberImg.memID = '$currID' AND members.memberId = memberImg.memID;", $db);


Thanks for everyones help,
~cheryl

Reply With Quote
  #5  
Old March 28th, 2003, 03:45 PM
NetproHosting NetproHosting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Apex, NC, USA
Posts: 31 NetproHosting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to NetproHosting
RE: help with join mysql - php

Hi Cheryl,

Glad that worked out for you. If it matters to you, I know with Oracle, the WHERE condition is processed from last to first. I'm not sure if mySQL is the same, but if it is, you might get a performance boost by rearranging the WHERE condition as:

$sql_result = mysql_query("SELECT *, memberImg.filename,memberImg.ID
FROM members,memberImg where members.memberId = memberImg.memID AND memberImg.memID = '$currID' ;", $db);

This way, the first slice is to narrow down the memberImg records to only those that match the memID of $currID, and then perform the join to members with that smaller subset.

Probably negligable, but with very large recordsets, it might help.

Good luck!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > help with join mysql - php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway