简体   繁体   中英

Get all Usernames by IP row from MySQL

So, everytime when someone registers on my server, their IP get's saved on ROW named "IP".

I want to get, every "USERNAME" row, by the same "IP" row saved.

Eg: Accounts: Mike, John are saved on IP 127.0.0.1

I want to select IP 127.0.0.1 and show me Mike, John.

Currently I did this:

$sql10 = "SELECT IP, username, pHour FROM users  order by pHour DESC LIMIT 5;";
$results10 =  array();
$result10 = mysqli_query($con,$sql10);

$results10 = mysqli_fetch_all($result10, MYSQLI_ASSOC);

$output10 = '';

foreach ($results10 as $row) {
    $output10 .= ' ' . $row['username'] . ' and ' . $row['pHour'] . '
';
}

I think that, I should add

SELECT username, IP, pHour FROM users WHERE IP = '$row['IP']' order by pHour

I'm on a good way to do it or not even close?

Simply, I want to get every username and pHour from the row 'IP'

You should add where condition for filter the rows ip

assuming your ip column is saved in a string column named ip

$sql10 = "SELECT username, pHour 
            FROM users 
            where ip = '127.0.0.1'
            order by pHour DESC LIMIT 5;";

you could use for passing the ip as a var

    $sth = $dbh->prepare('SELECT username, pHour 
        FROM users
        where ip = ?');
    $sth->bind_param("s",  $your_ip_var);

    $sth->execute();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM