There is a table in the database, each element of the table is displayed on the pages in a loop with a unique id, it turns out like this: Ivan, Andrei, Anton, the names are links to the message, that is, the message from Ivan is stored in the database. Ivan ", opened the page with the message. How to implement correctly? _ _ _ _ _ _ _ __-

id of message whom email 1 azon Почему меня забанили? admin 2 anna За что меня забанили?? admin angers@mail.ru 3 addon Я не нарушал правил! admin angers@mail.ru 
  • And if two Ivan? - Vfvtnjd
  • ID 1 | Ivan | Post ID 2 | Ivan | Message ID 3 | Ivan | Message ------------------------- - angers777
  • Yes, at least three. See [answer] [1]. [1]: hashcode.ru/questions/130431#130433 - knes
  • Mm .. I just understood that the id varchar field contains user names, I wanted to clarify this. Sorry if che. And so, I support @knes - a. - Vfvtnjd
  • varchar id is not the best option: it runs faster by numbers. Although it is impossible to completely exclude the possibility of use, but most often there is a hash in this case. - knes

1 answer 1

users:

USER_ID | USER_NAME
1 | Ivan
2 | Andrew
3 | Anton
4 | Sergei

messages

Message_id | User_id | text

Normalization is our all. =)

 //Выборка сообщений 'Select `text` from `messages` where `user_id`='.intval($_GET['id']); // //Выборка ссылок $res = mysql_query('select `USER_ID`,`USER_NAME` from `users`'); while($row = mysql_fetch_object($res)){ pritf('<a href="?id=%d">%s</a>',$row->USER_ID,$row->USER_NAME); } 
  • Why do i tell a message? Not needed, if the sample will always be for ALL user messages. But need, if you need to request a link to one. - knes
  • Conclusion: 202020202020 - angers777
  • Tables in the studio. The first three lines are sufficient. - knes
  • Added on top - angers777
  • fetch_object is better not to use without special need. Be there 1000 users, all your memory will burn out - Snow