Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8800381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:34:26+00:00 2026-06-14T00:34:26+00:00

I have a query (below) that will check for a match in 3 tables.

  • 0

I have a query (below) that will check for a match in 3 tables. All 3 tables have the columns UID and IPADDRESS; the third table also has USERNAME. How can I change the query below to populate the variable $username with a unique list of usernames that matched the ipaddress?

So in each of the tables UID where the ipaddress matched could be say 2, 3, 6, 6, 23, 2, 6 because there are multiple entries and someone may have spoofed others ip’s. What i’d like is the query to populate $username with the usernames that match the UIDs 2, 3, 6, 23 (unique list). I have to tell you I’m completely new to MySQL and queries. Here’s the query:

error_reporting(E_ALL & ~E_NOTICE & ~8192);
$UAM = strtoupper($_SERVER['HTTP_USER_AGENT']);
$ips = strtoupper($_SERVER['REMOTE_ADDR']);

$myquery= "select sum(total)
FROM (SELECT count(*) as total,userid
      FROM " .TABLE_PREFIX."memberviews v
      where v.ipaddress = '$ips'
      union all
      SELECT count(*) as total,userid
      FROM " .TABLE_PREFIX."membervisits v1
      where v1.ipaddress = '$ips'
      union all
      SELECT count(*) as total,userid
      FROM " .TABLE_PREFIX."user v3
      where v3.ipaddress = '$ips'
      )src";

$result = mysql_query($myquery);
$rowCount = mysql_num_rows($myquery);
$row = mysql_fetch_array($myquery);
$username = $row['userid'];

    If($rowCount !=0){
      $fp = fopen("logtext.txt", "a");
$DateOfRequest = date('m-d-Y H:i:s');
fwrite($fp, "Registration Attempt\n\nDate: . $DateOfRequest . \nMatched Member: . $username . \nWith User Agent:  . $UAM . \nIP: . $ips . \n\n");
    }
mysql_free_result($myquery);

Currently the query works in as much as it writes the file. All help appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:34:27+00:00Added an answer on June 14, 2026 at 12:34 am

    If I’m understanding your question correctly, this will get you the list of usernames associated with the IP address:

    SELECT username
      FROM uses AS u
      JOIN (SELECT userid
              FROM memberviews AS v1
             WHERE v1.ipaddress = $ips
            UNION
            SELECT userid
              FROM membervisits AS v2
             WHERE v2.ipaddress = $ips
            UNION
            SELECT userid
              FROM user AS v3
             WHERE v3.ipaddress = $ips
           ) AS v ON u.userid = v.userid
    

    I’ve un-PHP’d the SQL, for the most part — $ips marks where the IP address would be needed. The UNION (without ALL) eliminates duplicate user ID values; the list of unique user IDs is joined with the User table to generate the corresponding user names.

    Note that this will generate multiple rows, one per user name. Your question is ambiguous between user ID and user name in the output; if you only need the number, you only need the UNION sub-query as the main query. There are MySQL mechanisms such as GROUP_CONCAT that can create a single value from a list. Read the manual.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Sql-Server, and I have the below query which returns all columns that
I have two tables described below. What I need is a single query that
I have a query below that I use to retrieve the records not updated
I have the query below that when run it says that 325 rows were
I have an SQL query (below) that essentially takes a student from tbStudents, and
The query below returns rows that have both loginid and ip2 in the bumps
I have a query that returns a result set similar to the one below:
I have below a working query that needs to be simplified. The reason is
What I have is a mySQL query that will select some drinks and return
I have a MySQL query below that I'm using to get events for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.