Jump to content

Compare 2 values from diferent tables


RazorMaster

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.