I have to mysql queries that I need to combine:
First query will list down all usernames and passwords:
$query=mysql_query("SELECT Username, Password from user");
while($row = mysql_fetch_array($query)) {
echo $row['Username'].' '.$row['Password'];
}
Second will just print the password that corresponds to a certain username:
$user=$_SESSION['user'];
$query2=mysql_query("SELECT Username, Password from user WHERE Username = '$user'");
while($row2 = mysql_fetch_array($query2))
{
echo $row2['Password'];
}
How can I do that? Thanks!
This should do it.
$query=mysql_query("SELECT Username, Password from user");
$user=$_SESSION['user'];
while($row = mysql_fetch_array($query)) {
echo $row['Username'].' '.$row['Password'];
if ($row['Username'] == $user) {
echo $row['Password'];
}
}
Your first result array has already the answer. I am assuming your username is unique. So you can get combine them like this.
$user=$_SESSION['user'];
$query=mysql_query("SELECT Username, Password from user");
while($row = mysql_fetch_array($query)) {
echo $row['Username'].' '.$row['Password']."<br />";
if($row['Username']==$user)echo "THIS IS THE PASSWORD: ".$row['Password'];
}
Are they the hash passwords? Or do you do any kind of encryption?
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.