update multiple rows with multiple columns using loop

hi mate,

i have this query statement

UPDATE kai
SET `0522` = CASE WHEN `0522` IS NULL OR '0' THEN '' ELSE '1' END,
`0529` = CASE WHEN `0529` IS NULL OR '0' THEN '' ELSE '1' END,
`0605` = CASE WHEN `0605` IS NULL OR '0' THEN '' ELSE '1' END,
`0610` = CASE WHEN `0610` IS NULL OR '0' THEN '' ELSE '1' END,
`0610b` = CASE WHEN `0610b` IS NULL OR '0' THEN '' ELSE '1' END,
`0612` = CASE WHEN `0612` IS NULL OR '0' THEN '' ELSE '1' END,
`0619` = CASE WHEN `0619` IS NULL OR '0' THEN '' ELSE '1' END,…

update multiple rows with multiple columns using loop

Grouping by two columns in a table

I'm trying to create a very simple messaging system for a website and I am trying to group conversations by from or to using a single SQL statement. I have simplified the statement I am trying to use below:

$ messages_query = "SELECT * FROM tbl_messages WHERE from_id='$ current_user' OR to_id='$ current_user' GROUP BY from_id, to_id ORDER BY message_date DESC";

But ofcourse the grouping is a bit off. How would I get it to group by sender/receiver?