Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13513050 - Fikri Aulia #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
require('includes/config.php');
include('includes/header.php');
//include('js/javasript.js');
$qid = $_GET['id'];
$query = "SELECT * FROM question WHERE id = '".$qid."'";
$data = mysql_query($query);
?>

<h1>Question...</h1>
<?php while($record = mysql_fetch_array($data)): ?>
<p> <div class = clearfix>
<vote>
<a href="javascript:vote(<?php echo $record['id'] ?>, 'question', 'up')"><img src="css/up.png" width="20" height="20"></a> <br>
<font size= 4 id="qvote"><?php echo $record['vote'] ?></font><br>
<a href="javascript:vote(<?php echo $record['id'] ?>, 'question', 'down')"><img src="css/down.png" width="20" height="20"></a> <br>
</vote>
<question>
<p> <?php echo $record['content'] ?> </p>
<other>
<p> asked by
<name> <?php echo $record['name'] ?> </name> | <edit> <a href= "ask_question.php?id=<?php echo $record['id'] ?>">edit </a> </edit> | <delete> <a href= "delete.php?id=<?php echo $record['id']; ?>">delete </a> </delete>
</p>
</other>
</question>
</div>
</p>
<?php endwhile; ?>

<?php
$count = 0;
$query = "SELECT * FROM answer WHERE q_id = '".$qid."'";
$data = mysql_query($query);
while($record = mysql_fetch_array($data)){
if ($record['q_id'] == $qid){
$count = $count+1;
}
}
?>

<font size= 6 > <?php echo $count ?> Answer</font>
<svg height= 2 width= 800 > <line x1= 0 y1= 0 x2= 800 y2= 0 style= stroke:rgb(0,0,0);stroke-width:8 /> </svg> <br> <br>

<?php if($count > 0){ ?>
<?php
$query = "SELECT * FROM answer WHERE q_id = '".$qid."'";
$data = mysql_query($query); ?>
<?php while($record = mysql_fetch_array($data)): ?>
<div class=clearfix>
<nvote>
<a href="javascript:vote(<?php echo $record['id'] ?>, 'answer', 'up')"><img src="css/up.png" width="20" height="20"></a> <br>
<font size= 4 id=<?php echo $record['id']?> ><?php echo $record['vote'] ?></font><br>
<a href="javascript:vote(<?php echo $record['id'] ?>, 'answer', 'down')"><img src="css/down.png" width="20" height="20"></a> <br>
</nvote>
<question>
<font><?php echo $record['content'] ?></font>
<other>
<p> answered by <name> <?php echo $record['name'] ?> </name> </p>
</other>
</question>
</div>
<svg height= 2 width= 800 > <line x1= 0 y1= 0 x2= 800 y2= 0 style= stroke:rgb(0,0,0);stroke-width:8 /> </svg> <br> <br>
<?php endwhile; ?>
<?php } ?>


<font size="10">Your Answer</font>
<form action="insert_answer.php?id=<?php echo $qid ?>" method="post">
<input type="text" name="fname" placeholder="Name" ><br>
<input type="text" name="femail" placeholder="Email" ><br>
<input type="text" name="fcontent" ><br>
<input type="submit" name="submit" value="Post">
</form>
<?php include ('includes/footer.php'); ?>
20 changes: 20 additions & 0 deletions ask_question.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
require('includes/config.php');
include('includes/header.php');
$pid = $_GET['id'];
?>
<div>
<font size="6"> What's your question? </font> <br>
<svg height="2" width="800">
<line x1="0" y1="0" x2="800" y2="0" style="stroke:rgb(0,0,0);stroke-width:8" />
</svg> <br> <br>

<form action="insert_question.php?id=<?php echo $pid ?>" method="post">
<input type="text" name="fname" placeholder="Name" ><br>
<input type="text" name="femail" placeholder="Email" ><br>
<input type="text" name="fquestiontopic" placeholder="Question Topic" ><br>
<input type="text" name="fcontent" ><br>
<input type="submit" name="submit" value="Post">
</form>
</div>
<?php include('includes/footer.php');?>
Binary file added css/down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*----------------css untuk warna kata--------------*/
name{
color:blue;
}
askhere{
color:orange;
}
edit{
color:orange;
}
delete{
color:red;s
}

/* margin */
margin{
margin: 75px 50px 0px;

}

#wrapper {
margin: 0 auto;
max-width: 800px;
}
.clearfix {
overflow: auto;
}

vote{
float: left;
width : 50px;
clear: left;
/*border: 3px solid red;*/
}

question{
float: left;
width : 750px;
/*border: 3px solid red;*/
}

questionm3{
float: left;
width : 650px;
/*border: 3px solid red;*/
}


nvote{

float: left;
width : 50px;
clear: left;
/*border: 3px solid red;*/
}
nanswers{
float: left;
width : 90px;
/*border: 3px solid red;*/
}
other{
text-align: right;
width : 400px;
/*border: 3px solid red;*/
}


Binary file added css/up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions data base
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
-- phpMyAdmin SQL Dump
-- version 4.2.11
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Oct 14, 2015 at 06:58 AM
-- Server version: 5.6.21
-- PHP Version: 5.6.3

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 utf8 */;

--
-- Database: `coppeng`
--

-- --------------------------------------------------------

--
-- Table structure for table `answer`
--

CREATE TABLE IF NOT EXISTS `answer` (
`id` int(11) NOT NULL,
`q_id` int(11) NOT NULL,
`name` varchar(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_unicode_520_ci NOT NULL,
`vote` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `answer`
--

--
-- Table structure for table `question`
--

CREATE TABLE IF NOT EXISTS `question` (
`id` int(11) NOT NULL,
`name` varchar(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(60) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`topic` varchar(140) CHARACTER SET utf8 COLLATE utf8_unicode_520_ci NOT NULL,
`content` text CHARACTER SET utf8 COLLATE utf8_unicode_520_ci NOT NULL,
`vote` int(11) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `question`
--

--
-- Indexes for dumped tables
--

--
-- Indexes for table `answer`
--
ALTER TABLE `answer`
ADD PRIMARY KEY (`id`);

--
-- Indexes for table `question`
--
ALTER TABLE `question`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `answer`
--
ALTER TABLE `answer`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=12;
--
-- AUTO_INCREMENT for table `question`
--
ALTER TABLE `question`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=7;
/*!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 */;
9 changes: 9 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
require('includes/config.php');
$q_id = $_GET['id'];
$query1 = "delete from question where id = '".$q_id."'";
$query2 = "delete from answer where q_id = '".$q_id."'";
mysql_query($query1);
mysql_query($query2);
header("Location: question_list.php");
?>
32 changes: 32 additions & 0 deletions function/vote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
$servername = "localhost";
$username = "Fikri";
$password = "";
$dbname = "mydata";

$conn = new mysqli($servername, $username, $password, $dbname);

$id = $_POST['id'];
$qa = "";
$ud = "";

if ($_POST['ud'] === "up") {
$ud = "+1";
} else {
$ud = "-1";
}
$qaid = "id";
if ($_POST['qa'] === "question") {
$qa = "question";
} else {
$qa = "answer";
}

$vote = "UPDATE $qa SET vote = vote $ud WHERE $qaid = $id";
$conn->query($vote);
$select = "SELECT vote FROM $qa WHERE $qaid = $id";
$result = $conn->query($select);
$count = $result->fetch_array(MYSQLI_ASSOC)['vote'];

echo $count;
?>
11 changes: 11 additions & 0 deletions includes/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
$server = "localhost";
$username = "Fikri";
$password = "";
$basisdata = "mydata";
$link = @mysql_connect($server, $username, $password);
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}
mysql_select_db($basisdata,$link);
?>
3 changes: 3 additions & 0 deletions includes/footer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
</div>
</body>
<html>
10 changes: 10 additions & 0 deletions includes/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Simple Stack Exchange</title>
<link rel="stylesheet" media="screen" href="css/style.css" >
<script src="js/vote.js"></script>
</head>
<body>
<div id = "wrapper">
<Center> <h1><a href="question_list.php">Simple Stack Exchange</a></h1> </center>
21 changes: 21 additions & 0 deletions insert_answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
require('includes/config.php');
include('includes/header.php');
//include('js/javasript.js');
$qid = $_GET['id'];
/*
$name = $_GET['name'];
$email = $_GET['mail'];
$content = $_GET['content'];*/


$name = trim($_POST["fname"]);
$email = trim($_POST["femail"]);
$content = trim($_POST["fcontent"]);
$query = "SELECT * FROM question WHERE id = '".$qid."'";
$data = mysql_query($query);
$sql = "INSERT INTO answer VALUES ('','".$qid."','".$name."', '".$email."', '".$content."', 0)";
mysql_query($sql);
mysql_close($link);
header("Location: question_list.php");
?>
24 changes: 24 additions & 0 deletions insert_question.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
require('includes/config.php');
include('includes/header.php');
//include('js/javasript.js');
$qid = $_GET['id'];
/*
$name = $_GET['name'];
$email = $_GET['mail'];
$content = $_GET['content'];*/


$name = trim($_POST["fname"]);
$email = trim($_POST["femail"]);
$topic = trim($_POST["fquestiontopic"]);
$content = trim($_POST["fcontent"]);
if ($qid == -1){
$sql = "insert into question values('','".$name."', '".$email."', '".$topic."', '".$content."', 0)";
} else {
$sql = "update question set name = '".$name."', email = '".$email."', topic = '".$topic."', content = '".$content."' where id = '".$qid."'";
}
mysql_query($sql);
mysql_close($link);
header("Location: question_list.php");
?>
15 changes: 15 additions & 0 deletions js/vote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function vote(ID, qa, updown){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4 && xhttp.status === 200) {
if (qa == 'question') {
document.getElementById("qvote").innerHTML = xhttp.responseText;
} else {
document.getElementById(ID).innerHTML = xhttp.responseText;
}
}
};
xhttp.open("POST", "./function/vote.php", true);
xhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhttp.send("id=" + ID + "&qa=" + qa + "&ud=" + updown);
}
67 changes: 67 additions & 0 deletions question_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
require('includes/config.php');
include('includes/header.php');
?>
<center>
<form action="question_list.php" method="get">
<input type="text" name="search" >
<input type="submit" value="Search"> <br>
</form>
if you can't find what you are looking for
<a href="ask_question.php?id=-1">
<askhere> Ask Here </askhere>
</a>
</center>
<br />
<font size="5"> Recently Asked Questions </font> <br>

<?php
$sql = "SELECT * FROM question";
$data = mysql_query($sql);
?>

<?php while($record = mysql_fetch_array($data)):?>
<svg height= 2 width= 800 > <line x1= 0 y1= 0 x2= 800 y2= 0 style= stroke:rgb(0,0,0);stroke-width:8 /> </svg> <br> <br>
<div class=clearfix>
<nvote>
<center>
<p> <?php echo $record['vote'] ?> </p>
<p>Votes</p>
</center>
</nvote>

<nanswers>
<center>
<?php
$nanswers = 8;
?>
<?php
$count = 0;
$qcount = "SELECT * FROM answer WHERE q_id = '".$record['id']."'";
$dcount = mysql_query($qcount);
while($rcount = mysql_fetch_array($dcount)){
if ($rcount['q_id'] == $record['id']){
$count = $count+1;
}
}
?>
<p><?php echo $count ?> </p>
<p>Answer</p>
</center>
</nanswers>

<questionm3>
<a href = answer.php?id=<?php echo $record['id'];?> >
<font> <?php echo $record['topic'] ?> </font>
</a>
<other>
<p> asked by
<name> <?php echo $record['name'] ?> </name> | <edit> <a href= "ask_question.php?id=<?php echo $record['id'] ?>">edit </a> </edit> | <delete> <a href= "delete.php?id=<?php echo $record['id']; ?>">delete </a> </delete>
</p>
</other>
</questionm3>
</div> <br>
<?php endwhile; ?>
<?php mysql_close(); ?>

<?php include ('includes/footer.php'); ?>