我正在尝试使用chatrooms.php来选择要进入的聊天室,并且聊天室都有一个id例如聊天室1 id = 1和聊天室2 id = 2现在我想使用chatrooms.php来进入href用户选择chatoom的chatroom和chatroom.php有2个php文件用于功能whihc
This is the chatrooms.php let user to select the chat rooms
Once you select chat room the url id will change based on what chat room you choose
我正在做一个多聊天室,它只会加载你所在的聊天室
这是chatrooms.php:
<table class="table table-hover">
<?php
include '../config.php';
$sql = mysqli_query($connection, "SELECT * FROM chatroom");
while($row = mysqli_fetch_array($sql)) {
?>
<tr>
<td>
<a href="chatRoom.php?chatroomID=<?php echo $row['id']; ?>">
<div>
<p>
<?php echo ($row['name']); ?>
</p>
</div>
</a>
</td>
</tr>
<?php
}
?>
</table>
这是chat.php:
<?php
include '../config.php';
include'login.php';
$userID = $_SESSION['id'];
$message = $_GET['message'];
$chatroomID =$_GET['chatroomID'];
date_default_timezone_set('Asia/Kuala_Lumpur');
$today = date("Y-m-d H:i:s");
mysqli_query ($connection,"delete from chat where date < DATE_SUB(NOW() , INTERVAL 1 MONTH)");
$sql = mysqli_query($connection,"INSERT INTO chat(`user_id`, `chat`,`date`)VALUES('$userID', '$message','$today')")or die(mysqli_error($connection));
$chatID= mysqli_insert_id($connection);
$sql2 = mysqli_query($connection,"INSERT INTO chatroom_chat(chatroom_id,chat_id)VALUES('$chatroomID','$chatID')")or die(mysqli_error($connection));
$sql1= "SELECT * FROM (
SELECT * FROM chat ORDER BY id DESC LIMIT 0,40
) sub
ORDER BY id ASC ";
$result = mysqli_query($connection, $sql1);
$sql3 = mysqli_query($connection, "SELECT * FROM user WHERE id = '$userID'");
while($row = mysqli_fetch_array($sql3)) {
while($extract = mysqli_fetch_array($result)) {
$color = ($row['username'] == $_SESSION['username']) ? '#FFFFFF' : '#66FFFF';
$position = ($row['username'] == $_SESSION['username']) ? 'right' : 'left';
$border = ($row['username'] == $_SESSION['username']) ? ' 1px solid black ' : ' none ';
echo "<div class='msg-dateandtime' style='text-align:$position; float:$position;'> <div class='left-username' style='color:blue;'>" . $row['username'] ."</div>"
. "<div class='space'></div>"
. "<div class='right-date'> ". $extract['date'] ." </div></div>"
. "<div class='wrap-message' style='background-color:$color; border:$border; float:$position;'>"
. "<p style 'text-align=$position; margin:0; padding:0; text-align:left;'> ".$extract['chat']."</p></div>";
}
}
?>
这里是chatMessage.php:
<?php
include '../config.php';
include 'login.php';
$userID = $_SESSION['id'];
$chatroomID =$_GET['chatroomID'];
$sql="SELECT * FROM chatroom_chat where chatroom_id ='$chatroomID'";
$result1 = mysqli_query($connection, $sql);
while ($row = mysqli_fetch_array($result1)) {
$chat = $row['chat_id'];
$getChatData = mysqli_query($connection, "SELECT * FROM (SELECT * FROM chat WHERE id = '$chat' ORDER BY id DESC LIMIT 0,40)sub ORDER BY id ASC");
while($row3 = mysqli_fetch_array($getChatData)) {
$username = $_SESSION['username'];
$color = ($username == $_SESSION['username']) ? '#FFFFFF' : '#66FFFF';
$position = ($username == $_SESSION['username']) ? 'right' : 'left';
$border = ($username == $_SESSION['username']) ? ' 1px solid black ' : ' none ';
echo "<div class='msg-dateandtime' style='text-align:$position; float:$position;'> <div class='left-username' style='color:blue;'>" .$username."</div>"
. "<div class='space'></div>"
. "<div class='right-date'> ". $row3['date'] ." </div></div>"
. "<div class='wrap-message' style='background-color:$color; border:$border; float:$position;'>"
. "<p style 'text-align=$position; margin:0; padding:0; text-align:left;'> ".$row3['chat']."</p></div>";
}
}
?>
chatRoom.php只是html代码。 我的问题是我无法从href获取chatroomID到chatMessage.php和chat.php