Skip to content

Instantly share code, notes, and snippets.

Created August 4, 2017 22:10
Show Gist options
  • Save anonymous/7c1243bfceea2f64838648c44f30e14d to your computer and use it in GitHub Desktop.
Save anonymous/7c1243bfceea2f64838648c44f30e14d to your computer and use it in GitHub Desktop.
//var send_thread_id=<?php print $_GET['thread_id']; ?>;
function getParam() {
var url = location.href;
parameters = url.split("?");
params = parameters[1].split("&");
var paramsArray = [];
for ( i = 0; i < params.length; i++ ) {
neet = params[i].split("=");
paramsArray.push(neet[0]);
paramsArray[neet[0]] = neet[1];
}
var send_thread_id = paramsArray["thread_id"];
return send_thread_id;
}
var send_thread_id = getParam();
$(function(){
var hostUrl="http://localhost/chatter/getChat.php";
console.log(1);
//alert(send_thread_id);
$.ajax({
url:hostUrl,
type:'GET',
dataType:'json',
data:{
thread_id:send_thread_id
},
timeout:1000,
}).done(function(data) {
//console.log(title);
console.log(data["title"]);
//console.log(data["chat"]);
$('#title').prepend($('<h2></h2>').text(data["title"]));
var count = 0;
for (const thread of data["chat"]) {
count++;
show(thread.id,count,thread.name,thread.words);
}
})
.fail(function() {
console.log( "error" );
})
.always(function() {
console.log( "complete" );
});;
});
function syori(){
//$("#keijiban >span:last-child").css("color", "red");
var id = parseInt($("#keijiban >span:last-child").attr("code")) + 1;
//var id = parseInt($("#keijiban >span:last-child.code").text()) + 1;
//if(id == NaN){id = 1;alert("味蕾");}
//id = 1;
var name=document.js.name.value;
var words=document.js.words.value;
var thread_id=getParam();
$(function(){
var hostUrl="http://localhost/chatter/getChat.php";
var send_name=name;
var send_words=words;
var send_thread_id=thread_id;
//alert(send_thread_id);
$.ajax({
url:hostUrl,
type:'POST',
dataType:'json',
data:{name:send_name,words:send_words,thread_id:send_thread_id},
timeout:1000,
succces:function(data){
//alert("ok");
},
error:function(XMLHttpRequest,textStatus,errorThrown){
//alert("error " + textStatus);
}
});
});
show(id,id,name,words);
}
function show(id,count,name,words){
//$("#keijiban").append("<div><span class='code'>"+id+"</span>:"+name+"<br/>"+words+"<br/><br/></div>");
$('#keijiban').append($('<div class='+count+'></div>').text(id+":"+name));
//$('#keijiban').append($('<div class='+count+'></div>').text(item.name));
$('li').wrapInner('<span />');
$('#keijiban').append($('<div class='+count+'></div>').text(words));
//$("#"+count).before('<p>追加されました</p>');
//$("#"+count).after('<p>追加されました</p>');
$('div.' + count).wrapAll('<span code='+count+'></span>');
$('div.' + count).wrapAll('<pre code='+count+'></pre>');
}
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-3.2.1.min.js" ></script>
<script type="text/javascript" src="http://localhost/chatter/chat.js" ></script>
<title>プロフィール入力</title>
</head>
<body>
<div style="padding-left:100px">
<?php
session_start();
if(isset($_SESSION['login'])==false){
print '<div style="padding-top:10px;">';
print '<div style="padding-bottom:10px;">';
print '<a href="login.html">ログイン</a>';
//print '<a href="http:localhost/chatter/login.html">ログイン</a>';
print '</div>';
print '</div>';
}
?>
<!--<div>
<h3>書きこみ</h3>
</div>-->
<div style="padding-right:10px">
<div class="panel panel-success">
<div class="panel-heading"></div>
</div>
</div>
<div style="padding-right : 200px;">
<div class="panel panel-primary">
<div class="panel-heading"></div>
<div id = "keijiban"style="padding-left:20px">
<div id = "title"></div>
<div style="padding-bottom : 30px;"></div>
</div>
</div>
</div>
<div>
<form name="js">
<p>ユーザーネームを入力してください</p>
<input type="text"name="name"value=""style="width:100px"value="出来ない君"><br>
<p>内容を入力してください</p>
<input type="text"name="words"value=""style="width:500px"value="失敗"><br>
<br><input type="button"value="送信"onclick="syori()"><br><br>
</form>
</div>
<div style="padding-top : 20px;">
<a href="http://localhost/chatter/thread_open.php"
class="btn btn-default" role="button">スレッド管理画面に戻る</a>
</div>
</div>
</body>
</html>
<?php
$dsn = 'mysql:dbname=thread;host=localhost';
$user = 'root';
$password = '';
$dbh = new PDO($dsn,$user,$password);
$dbh->query('SET NAMES utf8');
// print '<div style="padding-right : 200px;">';
// print '<div class="panel panel-primary">';
// print '<div class="panel-heading"></div>';
// print '<div style="padding-left:20px">';
if(isset($_GET['thread_id']) || isset($_POST['thread_id'])){
if(isset($_GET['thread_id']))$thread_id = $_GET['thread_id'];
else if(isset($_POST['thread_id']))$thread_id = $_POST['thread_id'];
$sql = "SELECT thread_sub,thread_name FROM thread_all WHERE id=?";
$stmt = $dbh->prepare($sql);
$data[]=$thread_id;
$stmt->execute($data);
$rec = $stmt->fetch(PDO::FETCH_ASSOC);
$thread_sub = $rec['thread_sub'];
$thread_name = $rec['thread_name'];
//print '<div style="padding-bottom:30px;">';
//print '<h1>'.$rec['thread_name'].'</h1>';
//print '</div>';
if(isset($_POST['name']) && isset($_POST['words']) ){
$name=$_POST['name'];
$words=$_POST['words'];
$sql = 'INSERT INTO '.$thread_sub.' (name,words) VALUES ("'.$name.'","'.$words.'")';
//print'INSERT INTO '.$thread_sub.' (name,words) VALUES ("'.$name.'","'.$words.'")';
$stmt = $dbh->prepare($sql);
$stmt->execute();
}
}
$sql = 'SELECT*FROM '.$thread_sub.' WHERE 1';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$send = $stmt->fetchAll();
$send_array = array("chat" => $send , "title" => $thread_name);
print json_encode($send_array);
//print "<script>alert($send_array);</script>";
//print json_encode($thread_name);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment