I want to create a messaging system, here is my table:
(customers) userid int 11 primary key auto increment, username varchar 255, password varchar 255
(messages) mid int 11 primary key auto increment, from_id index customer.userid, to_id index customer.userid, message text
My question is if my session userid
is 11 how to display all the messages that are sent to my id?
What is the right code to use?
$stmt = $con->prepare("SELECT
message.*, customer.username AS from_id
FROM
message
INNER JOIN
customer
ON
customer.userid = message.from_id
");
$stmt->execute();
$rows = $stmt->fetchAll();