因此,我有以下代码供用户查找其他用户(请注意:为了使代码更具可读性,我在这里省略了aside标签):
<form action="index.php" method="POST">
<input id="search" type="text" placeholder="Search for Friends" name="search_name">
<input class="submit" type="submit" name="search-submit" value="Search">
</form>
然后我从数据库中获取数据,并将它们显示在一个称为$ output的变量中:
<?php
echo @$output;
?>
好吧,现在用户单击名称时,应该将聊天窗口而不是搜索结果放在一旁。因此,应将$ output替换为具有以下代码的聊天窗口:
<?php
if (isset($_POST['chat-submit'])) {
echo '<form method="POST" action="index.php" class="form-back">
<input class="back" type="submit" name="back" value="←Back">
</form>
<form>
<div class="chatwith"><h1><?php echo $username; echo ":"; ?></div>
<?php echo $finalstatus; ?>
<form action="index.php" method="POST" class="message-form">
<input class="message" type="text" placeholder="message" name="message">
<input class="submit" type="submit" name="message-submit" value="Send">
</form>';
}
?>
好的,所以两个代码都可以正常工作,但是当我单击$ outputs之一(并激活“聊天提交”)时,搜索框中的旧表格仍然存在。我如何删除旧表格,以便仅显示聊天窗口。是否有某种“只待一旁”?如有任何疑问,请问我。
答案 0 :(得分:1)
If you set $refresh to 0 you dont need the if. Because it is always 0. Do like this:
<?php
if(isset($_POST['chat-submit'])) {
echo '//here goes the chat-form but this is too long for this comment. But its the same as above'; }
else {
echo $output;
}
?>
答案 1 :(得分:0)
所以它现在可以工作了,这是@DieterKräutl提供的正确解决方案:
<?php
if(isset($_POST['chat-submit'])) {
echo '<form method="POST" action="index.php" class="form-back">
<input class="back" type="submit" name="back" value="←Back">
</form>
<form>
<div class="chatwith"><h1><?php echo $username; echo ":"; ?></div>
<?php echo $finalstatus; ?>
<form action="index.php" method="POST" class="message-form">
<input class="message" type="text" placeholder="message" name="message">
<input class="submit" type="submit" name="message-submit" value="Send">
</form>'; }
else {
echo $output;
}
?>