这是一个简单的聊天表
id| fromUserId| toUserId| message
让假数据John(45),Jane(46)和Mary(47)。说约翰同时与简和玛丽聊天。
John(45)开始与Jane(46)进行对话,所以数据看起来像这样:
id| fromUserId| toUserId| message
1 | 45 | 46 | wassup?
在第二种情况下,玛丽(47岁)开始与约翰(45)进行对话
id| fromUserId| toUserId| message
2 | 47 | 45 | wassup?
如何向John显示两个不同的对话?我使用此查询但不起作用:
<?php
$chatmsgQ="SELECT * FROM ve_chat c
WHERE c.isActive='1' AND c.fromUserId='$loginid_session'
OR c.toUserId='$loginid_session'";
$chatmsgresult= mysqli_query($db,$chatmsgQ);?>
使用时编辑
<ul class="dropdown-menu" style="overflow-x: hidden;">
<?php
$chatmsgQ="SELECT * FROM ve_chat c WHERE c.isActive='1' AND (c.fromUserId='$loginid_session' OR c.toUserId='$loginid_session') GROUP BY (c.fromUserId='$loginid_session' OR c.toUserId='$loginid_session')";
$chatresultse= mysqli_query($db,$chatmsgQ);
while($chatboxes= mysqli_fetch_array($chatresultse)){;?>
<li style="font-size: small; ">
<a style='width: 100% !important;' href='' data-toggle='modal' data-target='#chatModal'>
Chat with <?=$chatresultuseres['ProfileName'];?> | <?=$rowChat[0];?> Msg (s)
</a>
</li>
<?php } ;?>
</ul>
答案 0 :(得分:0)
在MySQL查询中使用括号
示例:
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var playSoundSwitch: UISegmentedControl!
var backgroundMusicPlayer: AVAudioPlayer?
var player:AVAudioPlayer = AVAudioPlayer()
@discardableResult func playSound(named soundName: String) -> AVAudioPlayer {
let audioPath = Bundle.main.path(forResource: soundName, ofType: "wav")
player = try! AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
player.play()
return player
}
@IBAction func catButtonPressed(_ sender: Any) {
if playSoundSwitch.selectedSegmentIndex == 0 {
playSound(named: "catSound")
}
}
@IBAction func dogButtonPressed(_ sender: Any) {
if playSoundSwitch.selectedSegmentIndex == 0 {
playSound(named: "dogSound")
}
}
@IBAction func birdButtonPressed(_ sender: Any) {
if playSoundSwitch.selectedSegmentIndex == 0 {
playSound(named: "birdSound")
print("bird sound")
}
}
@IBAction func playBackgroundMusicSwitchChanged(_ sender: Any) {
if (sender as AnyObject).selectedSegmentIndex == 0 {
backgroundMusicPlayer = playSound(named: "backgroundSound")
} else {
backgroundMusicPlayer?.stop()
backgroundMusicPlayer = nil
}
}
}