How to get information that is in 2 mysql tables

Asked

Viewed 67 times

-1

Table 01: $file

Table 02: $users

I want to do so, when a user is level ID = 30 display an msg

EXAMPLE, File 01 ($file->userid = 20 that is, that user id is in table 02, $users->id)


FILE TABLE inserir a descrição da imagem aqui


TABLE $USERS inserir a descrição da imagem aqui


I mean.. It would be like this: $file->userId$users->id->levelId ??

if (QUANDO ESSE ARQUIVO FOR DE UM USER LEVEL 30) {
	echo "teste";
}

  • The column userid is a foreign key? You know the clause join?

  • I have no idea what you’re talking about, just know that when I want to get information from the table, I put $file->filename for example.

  • Can you tell me how I do here in php? why I didn’t understand how to do..

  • 3

    Excuse me, but I think that 1 minute (2 at most) are insufficient for you to absorb the content of the 3 questions I mentioned and verify that you did not understand. Incidentally, PHP, in this problem, is irrelevant, since the question is SQL.

  • 3

    in mspaint, select "fill" option then "solid color", Now you can make a rectangle capping the hash of passwords...

Show 1 more comment

1 answer

1


Use the clause JOIN of SQL:

SELECT * FROM users as u
INNER JOIN file as f ON u.id = f.userId
WHERE u.level_id = 30

Explaining, line:

  1. Selects everything from the table users

  2. Together with the table file where the ids of each table are equal

  3. Adds a condition to return only those with the level equal to 30

Browser other questions tagged

You are not signed in. Login or sign up in order to post.