Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with SQL query. Need to distinct my results
    primarykey
    data
    text
    <p>I got table with my conversations, and i need to list alle conversation as topics. So if I'm the sender or the receiver, it should list it as one conversation. So between 2 users, it doesn't matter which role they got. </p> <hr> <p><strong>So if I got:</strong></p> <pre><code>1, me, mom, "hello mom, I'm good. How are you?", 1, 23/09-2011 2, mom, me, "hello son, how are you?", 1, 22/09-2011 3, me, dad, "hello dad, how are you?", 1, 20/09-2011 </code></pre> <hr> <p><strong>I want to show it like this:</strong></p> <pre><code>between You and Mom - Hello mom... - 23/09-2011 - 2 messeges between You and Dad - Hello dad... - 20/09-2011 - 1 message </code></pre> <hr> <p>I can't seem to figure out the query. Something with DISTINCT maybe.</p> <p>I hope you guys can help me out :)</p> <p>Update</p> <pre><code>CREATE TABLE IF NOT EXISTS `fisk_beskeder` ( `id` int(11) NOT NULL auto_increment, `fra` int(11) NOT NULL, `til` int(11) NOT NULL, `dato` varchar(50) NOT NULL, `set` int(11) NOT NULL default '0', `besked` text NOT NULL, `svar` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ; </code></pre> <p>PHP</p> <pre><code>$sql = mysql_query( "SELECT `fra`, `til`, `besked`, `dato`, `set`, `id` FROM fisk_beskeder WHERE til = ".$userid." OR fra = ".$userid." ORDER BY id DESC") or die(mysql_error()); </code></pre> <p>Update</p> <p>Okay, it's working now. Only thing i need is to get the newest data from the group.</p> <pre><code>SELECT count(id), `id`, `fra`, if(a.fra = $cfg_brugerid, a.til, a.fra) AS other, `til`, `besked`, `dato`, `set` FROM fisk_beskeder a WHERE fra = $cfg_brugerid OR til = $cfg_brugerid GROUP BY other ORDER BY a.id DESC </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload