General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help
View Poll Results: Is really difficult?
Yes 1 50.00%
No 1 50.00%
Intermediate 0 0%
It is really not 0 0%
Voters: 2. You may not vote on this poll


Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 10th, 2003, 07:52 AM
PHP041 PHP041 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Turkey
Posts: 10 PHP041 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PHP041
Table relations

I have two tables which one of them is users and second is reports. I have userID inserted into reports table to personel1, personel2,personel3,personel4,personel5.

I am trying to relate these two tables by sql code as follows;

$query3 =mysql_query("SELECT reports.personel1,reports.personel2,reports.person el3, reports.personel4,reports.personel5,users.userID,u sers.userLoginfrom reports,users WHERE $personel1 = users.userID or users.userID = $personel2 or users.userID = $personel3
or users.userID = $personel4 or users.userID = $personel5 AND reports.eventID = '$eventID' ");

while ($result3 = mysql_fetch_array($query3))
{
echo "<td>";

echo $result3["userLogin"] . "</td>";
}

ýt seems OK but here what happens. When I enter a new report with the same $eventID, I see the same personel names twice on the screen. When I run the script with AND instead of OR I see nothing on the screen. Should I do something different , any suggestions?

Best Regards

Reply With Quote
  #2  
Old October 10th, 2003, 09:21 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Try wrapping parentheses around all of your ORs to group them:

PHP Code:
 $query3 =mysql_query("SELECT reports.personel1,reports.personel2,reports.person  el3, reports.personel4,reports.personel5,users.userID,u  sers.userLoginfrom reports,users WHERE ($personel1 = users.userID or users.userID = $personel2 or users.userID = $personel3 or users.userID = $personel4 or users.userID = $personel5) AND reports.eventID = '$eventID' "); 


I would actually consider putting the personnel data in another table and having a table to join personnel ids to report ids to user ids, but maybe that doesn't suit your needs.

Reply With Quote
  #3  
Old October 11th, 2003, 09:10 PM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I would strongly recommend what dhouston says...

Use another table to manage the "personel" data.
__________________
The deal is not to know everything, but to know the email of the one who does.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Table relations


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 4 hosted by Hostway