Reply to topic
Match() function for MySQL database
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 770
Location: Newark, De
Reply with quote
The trading card site I'm building is coming along nicely. One of the next features I need implemented before I go live is a Match function that users can make use of in order to find other users with cards they want. The database table looks like this:

UserID - tinyint(4)
CardID - bigint (20)
own - tinyint (3)
want - tinyint(3)

When a user (say userID = jamie) inputs a card he wants, say card number 123, then the site checks to see if that entry exists and if not adds it like so:

userID **** CardID **** own **** want
-------------------------------------------------
jamie **** 123 **** 0 **** 1
dave **** 123 **** 1 **** 0
bob **** 123 **** 2 ****0

I would like it so when 'jamie' logs in and clicks on my 'Match' link it returns something like this:

Matches for user: Jamie

1. Bob has 2 cards that you need!
cardid: 123 trading: 2

2. Dave has 1 card that you need!
cardid: 123 trading: 1

Does anyone know how I could go about this? Any comments/suggestions are welcome!
cpnet


Joined: 03 Nov 2004
Posts: 135
Reply with quote
The SQL syntax may be a little off, but this should give you a starting point. (I'm assuming the table is called "ToTrade").

Code:
SELECT
  ownTT.UserID + " has " + ownTT.own + " card(s) that you need! CardId: " + ownTT.CardID + "; Trading: " + ownTT.own
FROM
  ToTrade AS wantTT
  INNER JOIN ToTrade AS ownTT ON
    wantTT.CardID = ownTT.CardID
WHERE
  wantTT.userID = "Jamie"
  AND wantTT.want > 0
  AND ownTT.userID <> "Jamie"
  AND ownTT.own > 0
[/code]
jamie
HostMySite Sales Rep
HostMySite Sales Rep

Joined: 19 Mar 2004
Posts: 770
Location: Newark, De
Reply with quote
Thanks, I'll take a look at that tonight. I was thinking it would be a lot more complex than that for some reason...
Match() function for MySQL database
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic