RazorMaster Posted May 5, 2008 Share Posted May 5, 2008 Hi, I'm trying to add code to compare 2 values from diferent tables. Imagine I have a Table1 ---------- seller_id seller_number Table2 ---------- Buyer_id buyer_number First I don't want sellers become buyers and buyers become sellers, so I have 2 diferent tables for users. This seller_number and buyer_number is like the personnal ID number that users must add while registering. I've successfully coded for fetch the database in case of repeted number, but only for sellers and other for buyers... Now I want: - If a user is trying to register with a number existing in table1 and existing in table2 do not allow and send warning message, or - If a seller is trying to register as buyer, checks number in both tables and if exist, do not allow and send warning message, or - If a buyer is trying to register as seller, checks number in both tables and if exist, do not allow and send warning message. Basicly, it fetch both tables and compare existing numbers with that is trying to be added... Any help, idea? Please? Thanks Quote Link to comment Share on other sites More sharing options...
craygo Posted May 5, 2008 Share Posted May 5, 2008 Why have 2 tables. Why not have one table and flag the user as a buyer or a seller. Then you could just query one table. Quote Link to comment Share on other sites More sharing options...
phorman Posted May 5, 2008 Share Posted May 5, 2008 Why not use a simple SQL JOIN SELECT STATEMENT: SELECT * from table1 join table2 on table1.seller_number = table2.buyer_number Then, if this statement returns any rows, you have your answer as to if the two numbers match in the database, and can then determine with the rest of your code whether a buyer or seller was trying to login and give the appropriate error. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.