How to get the user name corresponding to the MySQL ID PHP

How to get the user name corresponding to the MySQL ID PHP?
I am a novice is learning, would like to ask how this, hope big brother big sister who can write code to explain, thank you!!

Started by Lucine at November 03, 2016 - 2:46 AM

You mean SQL? What is the structure of your table, such as your table tablename as the following ID, username

SELECT id FROM tablename WHERE username='user1'


Reference resources: http://www.w3schools.com/sql/sql_select.asp

Posted by Leif at November 08, 2016 - 3:04 AM

<?php
$con = mysqli_connect("localhost", "username", "password") or die ("You cannot connect the database!<br>".mysqli_error());
$count_sql = "SELECT * FROM database.table where id='You specify the ID'";
$result = mysqli_query($con,$count_sql);
while ($row = $result->fetch_assoc())
{
    echo $row['The field name']
}

mysqli_close($con);
?>


Above is the MySQL data obtained from the sample PHP.

Posted by Eden at November 10, 2016 - 3:46 AM