From d1db8045595205bf83acd45793e73b851beb280d Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 00:58:59 +0700 Subject: [PATCH 01/22] Create index.php Fix layout and css --- index.php | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..d687a26 --- /dev/null +++ b/index.php @@ -0,0 +1,87 @@ + + + + + Home | Simple StackExchange + + + + +
+

Simple StackExchange

+
+
+ + + + +
+
+ + +
+

Cannot find what you are looking for? Ask here

+
+ +
+

Recently Asked Questions

+ + + "; + echo ""; + + echo ""; + + echo ""; + + + echo ""; + + echo ""; + echo ""; + echo ""; + } + + mysqli_close($conn); + + ?> +
"; + echo "

".$row[4]."

"; + echo "

Votes

"; + echo "
"; + echo "

".$row[5]."

"; + echo "

Answers

"; + echo "
"; + echo ''.'

'.$row[2].'

'; + echo "

".substr($row[3],0,180); + echo "

"; + echo '

asked by '.$row[1].' | '; + echo ''."edit".' | '. + 'delete'. + "

"; + echo "
+
+
+ + From ed2c6b80e7c746993a15fc71ff82d4c368730a66 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:02:00 +0700 Subject: [PATCH 02/22] Enable ask question --- ask_question.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ask_question.php diff --git a/ask_question.php b/ask_question.php new file mode 100644 index 0000000..00911bf --- /dev/null +++ b/ask_question.php @@ -0,0 +1,66 @@ + + + + + Ask Question | Simple StackExchange + + + + +
+

Simple StackExchange

+
+
+

What's your question?

+ +
+
+ + + + + +
+ + + +
+
+ + From b333644c1983a2fd7249dd99a4be5630834c8151 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:03:38 +0700 Subject: [PATCH 03/22] Enable edit question --- edit_question.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 edit_question.php diff --git a/edit_question.php b/edit_question.php new file mode 100644 index 0000000..310cd8a --- /dev/null +++ b/edit_question.php @@ -0,0 +1,73 @@ + + + + + Edit Question | Simple StackExchange + + + + +
+

Simple StackExchange

+
+
+

What's your question?

+ + + +
+
+ + + + + + +
; + + + + +
+
+ + From d5fe26ea195548c121e0f395f560b5dea4eaff69 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:06:48 +0700 Subject: [PATCH 04/22] Enable show question and add answer --- show_question.php | 139 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 show_question.php diff --git a/show_question.php b/show_question.php new file mode 100644 index 0000000..153fd60 --- /dev/null +++ b/show_question.php @@ -0,0 +1,139 @@ + + + + + Question | Simple StackExchange + + + + +
+

Simple StackExchange

+
+
+ + + + + "; + echo ""; + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ""; + echo ""; + echo ""; + + if ($answer > 0) { + $query2 = "SELECT email, content, vote, date, answerID FROM answer WHERE questionID = '$id'"; + $result = mysqli_query($conn, $query2); + + + if (! $result) { + die('Gagal ambil data: '.mysql_error()); + } + + echo ""; + echo ""; + echo ""; + + while($row = mysqli_fetch_row($result)) { + + + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ""; + echo ""; + echo ""; + } + } + + ?> +

".$row[1]."

"; + echo ""; + echo "

".$row[3]."

"; + echo ""; + echo "
"; + echo "

".$row[2]."

"; + echo "

asked by ".$row[0]. + " | edit | ". + 'delete'. + "

"; + echo "

".$answer." Answer"."

"; + echo "".$row[2]."

"; + echo ""; + echo "
"; + echo "

".$row[1]."

"; + echo "

answered by ".$row[0].""." at ".$row[3]."

"; + echo "
+ + +
+

Your Answer

+
+ + + + +
+ + +
+
+ + From 932ca0d1f5130239f7f5bef35e4d876f4fa1d7bb Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:07:57 +0700 Subject: [PATCH 05/22] Fix css --- style.css | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 style.css diff --git a/style.css b/style.css new file mode 100644 index 0000000..738d978 --- /dev/null +++ b/style.css @@ -0,0 +1,206 @@ +body { + font-family : sans-serif; + background-color: #f5f5f5; + font-size : 12px; +} + + +header { + text-align : center; + background-color: #ffffff; + margin: 50px 250px 0px 275px; + width: 800px; + height: 150px; + border: 1px solid black; + border-bottom-width: 0px; +} + +header p { + font-size: 36px; + padding-top: 10px; + +} + +.container { + width: 800px; + margin: 0px 0px 0px 275px; + position : absolute ; + text-align: center; + background-color: #ffffff; + border : 1px solid black; + border-top-width: 0px; + padding-bottom: 500px; +} + +#page_form { + height: 800px; +} + +#question { + width: 450px; + height: 30px; + margin-right: 10px; + box-shadow: 1px 2px 2px #000000; +} + +.find_question p { + margin-top: 5px; +} + +#search { + width: 80px; + height: 38px; + background-color: #FFFFFF; + font-size: 14px; + box-shadow: 1px 2px 2px #000000; +} + +#edit { + color : #FFD700; + text-decoration: none; +} + +#ask_here { + color : #FFD700; + text-decoration: none; +} + +a { + color : black; + text-decoration: none; +} +#title { + text-align: left; + margin: 0px 128px 0px 120px; + font-size: 24px; + margin-top: 0px; + border-bottom: 2px solid; +} + +.recently #title { + margin-top: 30px; + font-size: 18px; +} + + +.find_question input { + border: 3px solid black; + border-radius: 4px; +} + +#form input,textarea { + display : block; + margin: 5px 0px 0px 123px; + width: 540px; + border: 1px solid black; + height: 23px; + font-family : 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-size: 14px; +} + +#form { + margin-bottom: 20px; +} + +#form #post { + text-align: center; + width: 60px; + margin-left: 609px; +} + +#form #content { + height: 150px; +} + +#question_content { + text-align: justify; + +} + +#edit { + color: #FFD700; +} + +#delete { + color: red; +} + +#username { + text-align: right; +} + +#username #name { + color: blue; +} + +.answer_question #title { + text-align: left; + margin: 0px 128px 25px 120px; + padding-top: 15px; + padding-left: 5px; + margin-top: 0px; + border-top: 2px solid #778899; + border-bottom-width: 0px; + color: #778899; +} + +#title2 { + font-weight: bold; + text-align: left; + margin-bottom: 0px; + color: black; + +} + +#title3 { + text-align: left; + font-size: 20px; + margin-bottom: 0px; + +} + +.statistic { + padding: 0px 15px 0px 15px; + text-align: center; +} + +.statistic2 { + padding: 0px 35px 0px 35px; + text-align: center; + font-size: 28px; + color: gray; +} + +table { + margin: 0px 128px 25px 120px; +} + +th { + padding-bottom: 0px; + border-bottom: 2px solid black; +} + +#total_votes2 { + font-size: 28px; + color: gray; + margin: 5px 0px 5px 0px; +} + +.statistic2 p { + font-size: 28px; + margin: 5px 0px 5px 0px; +} + +img { + width: 20px; + height: 20px; + margin: 0px 0px 0px 0px; +} + +#up_button_answer, #up_button_question { + margin-top: 10px; +} + +#down_button_answer, #down_button_question { + margin-bottom: 10px; +} From b4a3bf3a09e16b9d019d53237dc045f039009204 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:08:36 +0700 Subject: [PATCH 06/22] Enable delete question --- delete_question.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 delete_question.php diff --git a/delete_question.php b/delete_question.php new file mode 100644 index 0000000..929faa7 --- /dev/null +++ b/delete_question.php @@ -0,0 +1,30 @@ + From f257f17cf6179a3136ab7c1691aea131a0ffb409 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:10:12 +0700 Subject: [PATCH 07/22] Function --- script.js | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 script.js diff --git a/script.js b/script.js new file mode 100644 index 0000000..69c2845 --- /dev/null +++ b/script.js @@ -0,0 +1,115 @@ +function validateEmail(email) { + var filter= /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ; + return filter.test(email); +} + + + +function validate_question_form() { + var x = document.forms["question_form"]["name"].value; + if (x == null || x == "") { + alert("Name must be filled out"); + return false; + } + var x = document.forms["question_form"]["email"].value; + if (x == null || x == "") { + alert("Email must be filled out"); + return false; + } + else if (! validateEmail(x)){ + alert("Please enter correct email address "); + return false; + } + var x = document.forms["question_form"]["question_topic"].value; + if (x == null || x == "") { + alert("Question Topic must be filled out"); + return false; + } + var x = document.forms["question_form"]["content"].value; + if (x == null || x == "") { + alert("Question Content must be filled out"); + return false; + } + +} + +function validate_answer_form() { + var x = document.forms["answer_form"]["name"].value; + if (x == null || x == "") { + alert("Name must be filled out"); + return false; + } + var x = document.forms["answer_form"]["email"].value; + if (x == null || x == "") { + alert("Email must be filled out"); + return false; + } + else if (! validateEmail(x)){ + alert("Please enter correct email address "); + return false; + } + var x = document.forms["answer_form"]["content"].value; + if (x == null || x == "") { + alert("Question Content must be filled out"); + return false; + } + +} +function confirmDelete() { + var delete = confirm("Are you sure want to delete this question ?"); + if (! delete) { + return false; + } +} + +function add_question_vote(id) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (xhttp.readyState == 4) { + if(xhttp.status == 200) { + document.getElementById("total_votes2").innerHTML = xhttp.responseText; + } + } + } + xhttp.open("POST", "add_question_vote.php?id=" + id, true); + xhttp.send(); +} + +function substract_question_vote(id) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (xhttp.readyState == 4) { + if (xhttp.status == 200) { + document.getElementById("total_votes2").innerHTML = xhttp.responseText; + } + } + } + xhttp.open("POST", "delete_question_vote.php?id=" + id, true); + xhttp.send(); +} + +function add_answer_vote(id) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (xhttp.readyState == 4) { + if(xhttp.status == 200) { + document.getElementById("total_votes3" + id).innerHTML = xhttp.responseText; + } + } + } + xhttp.open("POST", "add_answer_vote.php?id=" + id, true); + xhttp.send(); +} + +function substractAnswerVote(id) { + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (xhttp.readyState == 4) { + if(xhttp.status == 200) { + document.getElementById("total_votes3" + id).innerHTML = xhttp.responseText; + } + } + } + xhttp.open("POST", "substract_answer_vote.php?id=" + id, true); + xhttp.send(); +} From 0cd0835c3ef5a148042cd036e660dcbdb297b763 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:13:58 +0700 Subject: [PATCH 08/22] Database stackexchange --- stackexchange.sql | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 stackexchange.sql diff --git a/stackexchange.sql b/stackexchange.sql new file mode 100644 index 0000000..94c402b --- /dev/null +++ b/stackexchange.sql @@ -0,0 +1,105 @@ +-- phpMyAdmin SQL Dump +-- version 4.4.12 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Oct 15, 2015 at 08:12 PM +-- Server version: 5.6.25 +-- PHP Version: 5.6.11 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `stackexchange` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `answer` +-- + +CREATE TABLE IF NOT EXISTS `answer` ( + `questionID` int(4) NOT NULL, + `answerID` int(10) NOT NULL, + `name` varchar(25) NOT NULL, + `email` varchar(30) NOT NULL, + `content` text NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `vote` int(4) NOT NULL DEFAULT '0' +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `answer` +-- + +INSERT INTO `answer` (`questionID`, `answerID`, `name`, `email`, `content`, `date`, `vote`) VALUES +(9, 11, 'nursyahrina', 'nursyahrina17@gmail.com', 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', '2015-10-15 17:45:49', 0), +(9, 12, 'name3', 'name3@mail.com', 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', '2015-10-15 18:11:13', 0), +(9, 13, 'name3', 'name3@mail.com', 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', '2015-10-15 18:11:17', 0); + +-- -------------------------------------------------------- + +-- +-- Table structure for table `question` +-- + +CREATE TABLE IF NOT EXISTS `question` ( + `questionID` int(4) NOT NULL, + `name` varchar(25) NOT NULL, + `email` varchar(30) NOT NULL, + `question_topic` text NOT NULL, + `content` text NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `vote` int(4) DEFAULT '0', + `answer` int(4) NOT NULL DEFAULT '0' +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; + +-- +-- Dumping data for table `question` +-- + +INSERT INTO `question` (`questionID`, `name`, `email`, `question_topic`, `content`, `date`, `vote`, `answer`) VALUES +(9, 'name2', 'name2@mail.com', 'The question topic goes here2', 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', '2015-10-15 18:11:17', 0, 3), +(10, 'nursyahrina', 'nursyahrina17@gmail.com', 'The question topic goes here4', 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', '2015-10-15 18:11:41', 0, 0); + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `answer` +-- +ALTER TABLE `answer` + ADD PRIMARY KEY (`answerID`); + +-- +-- Indexes for table `question` +-- +ALTER TABLE `question` + ADD PRIMARY KEY (`questionID`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `answer` +-- +ALTER TABLE `answer` + MODIFY `answerID` int(10) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=14; +-- +-- AUTO_INCREMENT for table `question` +-- +ALTER TABLE `question` + MODIFY `questionID` int(4) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=11; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; From d00016eb8adf9b46fa51bdeea1e2a3795d2cdf38 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:21:49 +0700 Subject: [PATCH 09/22] Add answer vote --- add_answer_vote.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 add_answer_vote.php diff --git a/add_answer_vote.php b/add_answer_vote.php new file mode 100644 index 0000000..690cbd9 --- /dev/null +++ b/add_answer_vote.php @@ -0,0 +1,23 @@ + 0) + echo $row[0]; + exit; +?> From 686e8174d74c6350ceac6735fa0612c5b2597a4c Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:22:29 +0700 Subject: [PATCH 10/22] Add question vote --- add_question_vote.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 add_question_vote.php diff --git a/add_question_vote.php b/add_question_vote.php new file mode 100644 index 0000000..caee393 --- /dev/null +++ b/add_question_vote.php @@ -0,0 +1,23 @@ + 0) + echo $row[4]; + exit; + +?> From 2d1df04f64dbc39d12984dbbed3107d1e3604a5e Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:23:45 +0700 Subject: [PATCH 11/22] Substract answer vote --- substract_answer_vote.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 substract_answer_vote.php diff --git a/substract_answer_vote.php b/substract_answer_vote.php new file mode 100644 index 0000000..bcbfd10 --- /dev/null +++ b/substract_answer_vote.php @@ -0,0 +1,23 @@ + 0) + echo $row[0]; + exit; +?> From 2079746db2856796da7fe73e2d443a8bc62aa0a9 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 01:25:09 +0700 Subject: [PATCH 12/22] Substract question vote --- substract_question_vote.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 substract_question_vote.php diff --git a/substract_question_vote.php b/substract_question_vote.php new file mode 100644 index 0000000..1824b6d --- /dev/null +++ b/substract_question_vote.php @@ -0,0 +1,22 @@ + 0) + echo $row[4]; + exit; + +?> From c4e8dec0979312bbd7318aa164379704b2ae02f5 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:26:47 +0700 Subject: [PATCH 13/22] Enable add vote answer --- add_answer_vote.php => vote_up_answer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename add_answer_vote.php => vote_up_answer.php (85%) diff --git a/add_answer_vote.php b/vote_up_answer.php similarity index 85% rename from add_answer_vote.php rename to vote_up_answer.php index 690cbd9..8f1c6f0 100644 --- a/add_answer_vote.php +++ b/vote_up_answer.php @@ -10,7 +10,7 @@ $id = $_REQUEST["id"]; - $sql = "UPDATE answer SET vote = vote + 1 WHERE answerID='$id'"; + $sql = "UPDATE answer SET vote = vote+1 WHERE answerID='$id'"; $result = mysqli_query($conn, $sql); $sql = "SELECT vote FROM answer where answerID='$id'"; @@ -18,6 +18,6 @@ $row = mysqli_fetch_assoc($result); if (mysqli_num_rows($result) > 0) - echo $row[0]; + echo $row['vote']; exit; ?> From 603f8fd5c1ac11945a23ed11b2ce080a6a6a5116 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:28:04 +0700 Subject: [PATCH 14/22] Enable add vote question --- add_question_vote.php => vote_up_question.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename add_question_vote.php => vote_up_question.php (79%) diff --git a/add_question_vote.php b/vote_up_question.php similarity index 79% rename from add_question_vote.php rename to vote_up_question.php index caee393..30c46e9 100644 --- a/add_question_vote.php +++ b/vote_up_question.php @@ -1,6 +1,6 @@ 0) - echo $row[4]; + echo $row['vote']; exit; ?> From 2aa73b821f8320a73e33c70eda4d6cfbcf7bf576 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:30:08 +0700 Subject: [PATCH 15/22] Enable substract vote answer --- substract_answer_vote.php => vote_down_answer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename substract_answer_vote.php => vote_down_answer.php (96%) diff --git a/substract_answer_vote.php b/vote_down_answer.php similarity index 96% rename from substract_answer_vote.php rename to vote_down_answer.php index bcbfd10..68f7a03 100644 --- a/substract_answer_vote.php +++ b/vote_down_answer.php @@ -18,6 +18,6 @@ $row = mysqli_fetch_assoc($result); if (mysqli_num_rows($result) > 0) - echo $row[0]; + echo $row['vote']; exit; ?> From 19deebd7f509d0a3d12a0c94bf92b1c81d3b7ca1 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:31:04 +0700 Subject: [PATCH 16/22] Enable substract vote question --- substract_question_vote.php => vote_down_question.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename substract_question_vote.php => vote_down_question.php (94%) diff --git a/substract_question_vote.php b/vote_down_question.php similarity index 94% rename from substract_question_vote.php rename to vote_down_question.php index 1824b6d..b7ec946 100644 --- a/substract_question_vote.php +++ b/vote_down_question.php @@ -16,7 +16,7 @@ $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); if (mysqli_num_rows($result) > 0) - echo $row[4]; + echo $row['vote']; exit; ?> From 8ed8b43131021192591da24d6e60f1125c577695 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:31:43 +0700 Subject: [PATCH 17/22] Fix css --- style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/style.css b/style.css index 738d978..0b6f754 100644 --- a/style.css +++ b/style.css @@ -173,6 +173,7 @@ a { table { margin: 0px 128px 25px 120px; + width: 555px; } th { From 1c70ef34f04816389693d53c39334a9c190970b4 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:32:28 +0700 Subject: [PATCH 18/22] Fix layout css php --- show_question.php | 86 ++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/show_question.php b/show_question.php index 153fd60..ec32669 100644 --- a/show_question.php +++ b/show_question.php @@ -38,32 +38,34 @@ } $row = mysqli_fetch_row($result); $answer = $row[4]; + ?> + +

+ - echo ""; - echo "

".$row[1]."

"; - echo ""; + - echo ""; + + +

+ + - echo ""; - echo ""; - echo "

".$row[3]."

"; - echo ""; - echo ""; + +

+

asked by + at | edit | + delete +

+ - echo ""; - echo "

".$row[2]."

"; - echo "

asked by ".$row[0]. - " | edit | ". - 'delete'. - "

"; - echo ""; + - echo ""; + + + - echo ""; - echo ""; - echo ""; + 0) { $query2 = "SELECT email, content, vote, date, answerID FROM answer WHERE questionID = '$id'"; @@ -74,31 +76,37 @@ die('Gagal ambil data: '.mysql_error()); } - echo ""; - echo "

".$answer." Answer"."

"; - echo ""; + ?> + + +

Answer

+ + + + + - echo ""; + + +

+ + - echo ""; - echo "".$row[2]."

"; - echo ""; - echo ""; + +

+

answered by at

+ - echo ""; - echo "

".$row[1]."

"; - echo "

answered by ".$row[0].""." at ".$row[3]."

"; - echo ""; + - echo ""; + + + - echo ""; - echo ""; - echo ""; +

Your Answer

-
+ From 84bd3708b29f82ea7900bf7c7e53e31c470dd44e Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:34:39 +0700 Subject: [PATCH 19/22] Fix script for validation and vote --- script.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/script.js b/script.js index 69c2845..cb6ba39 100644 --- a/script.js +++ b/script.js @@ -33,6 +33,11 @@ function validate_question_form() { } +function confirm_delete_question() { + var x = confirm("Are you sure want to delete this question ?"); + return x; +} + function validate_answer_form() { var x = document.forms["answer_form"]["name"].value; if (x == null || x == "") { @@ -55,14 +60,8 @@ function validate_answer_form() { } } -function confirmDelete() { - var delete = confirm("Are you sure want to delete this question ?"); - if (! delete) { - return false; - } -} -function add_question_vote(id) { +function vote_up_question(id) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4) { @@ -71,11 +70,11 @@ function add_question_vote(id) { } } } - xhttp.open("POST", "add_question_vote.php?id=" + id, true); + xhttp.open("POST", "vote_up_question.php?id=" + id, true); xhttp.send(); } -function substract_question_vote(id) { +function vote_down_question(id) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4) { @@ -84,32 +83,32 @@ function substract_question_vote(id) { } } } - xhttp.open("POST", "delete_question_vote.php?id=" + id, true); + xhttp.open("POST", "vote_down_question.php?id="+id, true); xhttp.send(); } -function add_answer_vote(id) { +function vote_up_answer(id) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4) { if(xhttp.status == 200) { - document.getElementById("total_votes3" + id).innerHTML = xhttp.responseText; + document.getElementById("total_votes3"+id).innerHTML = xhttp.responseText; } } } - xhttp.open("POST", "add_answer_vote.php?id=" + id, true); + xhttp.open("POST", "vote_up_answer.php?id="+id, true); xhttp.send(); } -function substractAnswerVote(id) { +function vote_down_answer(id) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.readyState == 4) { if(xhttp.status == 200) { - document.getElementById("total_votes3" + id).innerHTML = xhttp.responseText; + document.getElementById("total_votes3"+id).innerHTML = xhttp.responseText; } } } - xhttp.open("POST", "substract_answer_vote.php?id=" + id, true); + xhttp.open("POST", "vote_down_answer.php?id="+1, true); xhttp.send(); } From d7860d3684fc95533b90239ba96d85a6aca8c9c6 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:35:14 +0700 Subject: [PATCH 20/22] Fix lay css php --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index d687a26..abc1313 100644 --- a/index.php +++ b/index.php @@ -14,7 +14,7 @@ "; echo '

asked by '.$row[1].' | '; echo ''."edit".' | '. - 'delete'. + 'delete'. "

"; echo ""; From 7efe50162588f64e655384a4c32608011ea199ea Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Fri, 16 Oct 2015 21:49:23 +0700 Subject: [PATCH 21/22] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c08b9d..0440824 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ Pengguna dapat mencari pertanyaan dengan melakukan search ke `judul` maupun `isi ### Penjelasan Teknis -`Silakan isi bagian ini dengan penjelasan anda, sesuai Petunjuk Pengerjaan di atas.` +Validasi form question dan answer keduanya menggunakan function javascript yang melakukan pengecekan apakah kolom form terisi dan cek alamat email apakah valid atau tidak, jika ada yang kosong atau tidak valid maka akan muncul box peringatan. +Vote up dan vote down menggunakan AJAX. Saat icon vote di click pada script akan membuat objek XMLHttpRequest yang mengambil nilai id dari question atau answer yang sedang di vote. Function akan mengambil meng-update nilai vote pada database dan mengambil nilai vote yang baru dari database kemudian mengubah nilai vote yang ditampilkan (sesuai nilai pada database) tanpa reload page. Function vote up dan down untuk question dan answer dipisahkan dan file phpnya juga terpisah untuk mempermudah pengerjaan. ### Knowledge From 5def33a22cf954fee3f79e1c0b891e16c5615076 Mon Sep 17 00:00:00 2001 From: nursyahrina Date: Thu, 29 Oct 2015 02:18:55 +0700 Subject: [PATCH 22/22] Vote Up and Down --- images/down.png | Bin 0 -> 817 bytes images/up.png | Bin 0 -> 753 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 images/down.png create mode 100644 images/up.png diff --git a/images/down.png b/images/down.png new file mode 100644 index 0000000000000000000000000000000000000000..fdbeffa1aa8f5a1dc60f48769db66e59773ce3c1 GIT binary patch literal 817 zcmV-11J3-3P)002J-1^@s6sQooP00001b5ch_0zklh z#Q*>R32;bRa{vGr5&!@f5&>tQ(oz5b02y>eSaefwW^{L9a%BKbX=8G4b8lvJAWvpy zX=7!7?KN=#00OZ|L_t(|+U?sdY{Ebk2XN#ha&i(`IXQ`}L{3g3k)SG(NF=hd5{X2S zQWAnhB9YrY@*pj1%eD9Qu6N=kWSO}4%e#L{kLzVwmazKuRbTu4e%oUo2JFMtgVa}= zreD3;YzAPF2dRZxfzu7^cs#zbKb}2I>Gr$scDwfn7EV{_aY}1^H+o<}9S(=J$0>$7 z?7C7c_78y%`$7%#J_RhCuDM6LRs3x856g#rG1P0Za6671pQ=fjODPtDZ5)M4^P$d* z6*!6&R+&^{IU4qHokuMe8^^vYVUMBy(HaYieJ}cUWU8jGEM8(k!INyqp-xqy-Wbb) zun&10xUg`#79E93cn!F*;EA?tVUOQ~2hy={JN|TRs-hJZe5e)l)EEZ1JgveAaWcMZ=3y=R()1h8={7w#w$Zx%VRP?0;%VgNg4s|V9 zaA0X7?BV64byzrEQ_WB6OO^d7#lo;ZY1)1l6``&TOLN$dRrjJC3&9dwL)`?H(pwzx z60$Q`2o@=VTIuRR8OVL#Tneyvz|K)aR|>LMpKR$yiFZgC8CuU$J9 zPS;!zDmJlhBUmC~uRGL@W8rpedy8XYYR$&55UlAfj#PK3Q^IQc!`{&3dW~W=4Exyh zT8(4z+~VN5{on)^6vr)&DTQ^Cz=End{y&)vb&^;$VINXiBN;55uIF1E38nRs!ph&` vXnOm>IV{|c_gfqhwY8DMLa>BNsOResV1NdlUc0Wg00000NkvXXu0mjftK)I; literal 0 HcmV?d00001 diff --git a/images/up.png b/images/up.png new file mode 100644 index 0000000000000000000000000000000000000000..cf3af9fcd1990f733bc3d6b52842ca4c933c7fc4 GIT binary patch literal 753 zcmV002G+1^@s6W1;4l00001b5ch_0zklh z#Q*>R32;bRa{vGr5&!@f5&>tQ(oz5b02y>eSaefwW^{L9a%BKbX=8G4b8lvJAWvpy zX=7!7?KN=#00MDIL_t(|+U=VwbiyzchLMxVN#rCFiL68-kw_#G6cRa!L{=h^NED}( zb2!M#$;mCZr`ZaGkd!=b9^!Ws@bTvx^xm}Q^LYzf@;sknd|enpB_uy2;|PnB^ZEQn zAY~P-;&3>;M_8QWSAi;XJRUzIEJmP31kQIIR+Vmqb>FI#0Sel+kFc&m4OpORnM7Fs zQorzEk#>DykUfT0&7QQX%;|Jm1r3X|rSm}Q%#gqD1q+J+*ocCnvWH_E94rB;qm#W& zsTWOP!LhX^dt0qqG;CFwEX&qGz#?zLsjK zq>e@QCXe4zajR%juVBGr78O$GB=H88DyeglnUKA9P~>0yNHZv!nbWYyr`=X9^(V6L zI15Xo)UC)~tJDpHq8YddYi9}8MVIV#ff`!^MYC`M7JQ>NC3T+c;Ricm93f}1EpN{%A^j1P>irD*>};vf&nPfR?z|N76mLAd}0Pw z%g{P3gi_Zgdtasg=r}H|z~U^QVNcgMEEse;2nw<@3JV6Dj)I~C+K~}hAW4U$&Xavx zJFMG{Vpr2-6FL;BE0Miyt5T0ZNpC{SfJ%GStd{6o7h18Wm1 zC@Oo_Q`IPS3E8uxUPMsrP3YTJEh4BZcdePQa{U{{t|qyIWniP&)%}t|qj^86mx+5tw00000NkvXXu0mjfAW}u0 literal 0 HcmV?d00001