Jump to content

SQL help


freeloader

Recommended Posts

Hi guys,

 

I have a table with 5 columns: username, ip, lastiplog, referer, referals

 

This query searches for double IPs and outputs them:

SELECT * FROM tb_users tb WHERE EXISTS(SELECT tb2.ip FROM tb_users tb2 WHERE tb.ip=tb2.ip AND tb.username<>tb2.username) order by ip

 

I'd like to have it search in the lastiplog column as well, how do I change that?

 

Secondly, I would like a query that outputs the number of referals the referer of the account I'm doing the search for has:

 

SELECT `referals` FROM `tb_users` WHERE username = $current_user.referer

 

Unfortunately, the above returns an error...

 

As an example: if $current_user is 'testuser', and testuser is refered by firstuser, I want to know the number of referals firstuser has.

Link to comment
Share on other sites

Problem 1:

 

I have 3 fields, username, ip and lastiplog

 

I need to search tables for double ip's in both ip and lastiplog where username differ.

 

Problem 2:

 

I have 3 fields, username, referer, referals

 

Let's take this as an example:

 

username - referer - referals

user1 - user2 - 20

user2 - user3 - 12

user3 - user10 - 10

 

When user2 is logged in, I want to run a query with which I can get the referals field of his referer. The referer of user2 is user3, I want to know the number of referals of user3 which is 10. Can I do this in one query?

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.