freeloader Posted June 15, 2008 Share Posted June 15, 2008 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 More sharing options...
freeloader Posted June 16, 2008 Author Share Posted June 16, 2008 I see this has been moved to the mysql section, anybody who can help me here? Link to comment https://forums.phpfreaks.com/topic/110326-sql-help/#findComment-566359 Share on other sites More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 sorry friend i cant get u can u explain it what u need? Link to comment https://forums.phpfreaks.com/topic/110326-sql-help/#findComment-566395 Share on other sites More sharing options...
freeloader Posted June 16, 2008 Author Share Posted June 16, 2008 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 More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 for ur problem 2: SELECT referals,(SELECT referer FROM `log` WHERE username='user2')as refers FROM `log` WHERE username=(SELECT referer FROM `log` WHERE username='user2') Link to comment https://forums.phpfreaks.com/topic/110326-sql-help/#findComment-566422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.