Hello i cant understand how i can send database info to user for example i want to send my note which contain (date, text, title and other info) and this info is under ID for ex. (123456) please someone explain me how i can do that or help me thank you :)

Member Avatar for diafol

If you have a db table ('notes') like so:

id | date | text | title | to | from

Then all you need to do is create a prepared statement (PDO or mysqli):

SELECT `id`, `date`, `title`, `text` ... FROM `notes` WHERE `to` = ? ORDER BY `date`  DESC 

Then bind the session user id to it - this is assuming that you have a user login system ad that you store the user's user_id in the session on successful login.

Obviously you can make it more sophisticated by getting the sender's name and by limiting this to say 20 notes (pagination):

SELECT n.id, n.date, n.title, n.text, u.username ... FROM `notes` AS n INNER JOIN `users` AS u WHERE n.to = ? ORDER BY n.date DESC LIMIT ?,?

If you have inbox and outbox tabs (like DW), it's a similar thing to do sent items:

SELECT n.id, n.date, n.title, n.text, u.username ... FROM `notes` AS n INNER JOIN `users` AS u WHERE n.from = ? ORDER BY n.date DESC LIMIT ?,?

If you want conversation type output:

SELECT n.id, n.date, n.title, n.text, u.username ... FROM `notes` AS n INNER JOIN `users` AS u WHERE n.to = ? OR n.from = ? ORDER BY n.date DESC LIMIT ?,?

This can be even more complicated is you have message statuses, like 'read', 'deleted', etc. Limitless options! This is fun stuff to play with.

hmm i get it but not at all, i have table kladilnica and im getting the values title, text, and date for ex. so in your example you have one more row which is to but i dont have that row in the database i dont understand what i need to do. Should i create one more row and that row to be the noteReceiver if yes, what if i want to send it to two users the note ?

Member Avatar for diafol

You have a few options for sending to multiple recipients, but the best is probably:

NOTES

id | date | text | title | sender_id

MESSAGES

note_id | recipient_id | status_id (PK on note_id and recipient_id)

That way you can send this to as many people as you like:

Note

1 | 2001-01-08 12:09:07 | Some text | This is a Title | 8

Messages (note #1 sent to users 5,6,9)

1 | 5 | 1
1 | 6 | 1
1 | 9 | 2

However you could do this in a number of ways as I said. You could also adapt it to create a group conversation - more like a chat or forum type communication.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.