MySQL + PHP: fetching data using foreign keys

后端 未结 4 1815
一整个雨季
一整个雨季 2021-01-14 08:21

I have 2 tables (Users, Wall). The UserID in the Wall table is a foreign key. How would I go about fetching the users details using this? (I want to fetch the users Forename

4条回答
  •  我在风中等你
    2021-01-14 08:56

    As here the main target are messages you write in a sql query first the table with message, in your example Wall table and the query can look like this: $result = mysql_query ("SELECT u.Forename, u.Surname, w.Message FROM Wall AS w INNER JOIN Users AS u ON(w.UserID=u.UserID)");

    Now when output use:




    Of course do the proper formatting.

提交回复
热议问题