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
https://forums.phpfreaks.com/topic/110326-sql-help/
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
https://forums.phpfreaks.com/topic/110326-sql-help/#findComment-566402
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.