E.Laemas 김 :
제가 원하는 설명해 보자.
나는 페이지의 변경없이 DB를 추가로 목록에 때 입력 값을 추가하려면 form
, 클릭하십시오 submit
.
그러나이 코드에서, 내가 추가 한 번 더 새로 고침, 또한 두 번 시간을 추가해야합니다.
내가 어떻게 할 수 있습니까?
<?php
$conn = mysqli_connect('127.0.0.1','MYID','MYPASS','MYDB');
$sql = "SELECT * FROM MYTABLE";
$rs = mysqli_query($conn, $sql);
$list = '';
while($row = mysqli_fetch_array($rs)) {
$list = $list."<li><a href=\"index.php?id={$row['id']}\">{$row['title']}</a></li>";
}
$article = array(
'title' => 'Welcome!',
'description' => 'Hello, Web!'
);
if (isset($_GET['id'])){
$filtered_id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT * FROM topic WHERE id={$filtered_id}";
$rs = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($rs);
$article['title'] = $row['title'];
$article['description'] = $row['description'];
}
if ($_POST['title'] != null){
$sql_in = "INSERT INTO topic (title, description, created) VALUES ('{$_POST['title']}', '{$_POST['description']}', NOW())";
$rs_in = mysqli_query($conn, $sql_in);
if ($rs_in === false) {
$msg = mysqli_error($conn);
} else {
$msg = 'Success.';
}
} else {
$msg = 'Fill in';
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WEB</title>
</head>
<body>
<h1><a href="index.php">WEB</a></h1>
<ol>
<?=$list?>
</ol>
<details>
<summary>Create</summary>
<form action="./index.php" method="POST">
<p><input type="txt" name="title" placeholder="title"></p>
<p><textarea name="description" placeholder="description"></textarea></p>
<p><input type="submit"></p>
<p><?=$msg?></p>
</form>
</details>
</body>
</html>
<h2><?=$article['title']?></h2>
<?=$article['description']?>
</body>
</html>
베이더 :
PHP에서 실시간은 일이 아니라 당신이 푸셔 같은 이벤트 서비스를 사용할 수있는 해결 방법은 https://pusher.com/docs 즉시 클라이언트 측에서 이벤트를 수신은.
다른 웹 사이트의 제공이 그래서 당신은 항상 Node.js를에 이벤트 서버를 구축 할 수 있습니다 또한 그들을 선택하기 전에 검색이 수행 C #을, 이동