baza+rating+komentarze

This commit is contained in:
s416267 2018-12-06 00:58:20 +01:00
parent 4447f6d55e
commit ddfd0dba08
6 changed files with 207 additions and 16 deletions

View File

@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Czas generowania: 01 Gru 2018, 22:48
-- Czas generowania: 06 Gru 2018, 00:50
-- Wersja serwera: 10.1.36-MariaDB
-- Wersja PHP: 7.2.11
@ -56,7 +56,8 @@ CREATE TABLE `comments` (
INSERT INTO `comments` (`comment_id`, `post_id`, `username`, `tekst`, `data_dodania`, `data_modyfikacji`) VALUES
(1, 18, 'użytkownik testowy 1', 'Komentarz Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec ipsum ultrices, condimentum elit nec, luctus neque. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec eget ullamcorper ante. Donec fermentum erat nisi, eu dapibus neque ultrices et. Sed at sapien consectetur, iaculis dui non, sagittis mi. Nam consequat tempus felis at pretium. Cras ut lacus id ipsum interdum ullamcorper. In eget urna sed orci aliquam consequat. Morbi iaculis eros vel orci imperdiet ornare. Nulla quis dignissim ante. Etiam non rhoncus lectus, sit amet porta nunc. Cras at ultrices diam. Aenean arcu sapien, efficitur quis rutrum in, euismod et turpis.', '2018-12-01 22:11:16', '2018-12-01 22:11:16'),
(2, 18, 'użytkownik testowy 2', 'Drugi komentarz ale krótki Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec ipsum ultrices, condimentum elit nec, luctus neque. ', '2018-12-01 22:12:04', '2018-12-01 22:12:04');
(2, 18, 'użytkownik testowy 2', 'Drugi komentarz ale krótki Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nec ipsum ultrices, condimentum elit nec, luctus neque. ', '2018-12-01 22:12:04', '2018-12-01 22:12:04'),
(5, 0, '', 'Sprawdzam czy dodawanie komentarzy działa, jeśli tak to bardzo się cieszę. Trzeba jeszcze ogarnąć żeby zaciągało użytkownika który jako zalogowany komentuje no i żeby nie wyświetlało opcji komentowania dla bobów, którzy nie są zalogowani :).', '2018-12-05 20:55:29', '2018-12-05 20:55:29');
-- --------------------------------------------------------
@ -89,6 +90,28 @@ INSERT INTO `post` (`post_id`, `blog_id`, `tytul`, `opis`, `tekst`, `image`, `da
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `rating`
--
CREATE TABLE `rating` (
`post_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`rating` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin2;
--
-- Zrzut danych tabeli `rating`
--
INSERT INTO `rating` (`post_id`, `user_id`, `rating`) VALUES
(0, 0, 5),
(0, 0, 5),
(0, 0, 3),
(0, 0, 1);
-- --------------------------------------------------------
--
-- Struktura tabeli dla tabeli `user`
--
@ -157,7 +180,7 @@ ALTER TABLE `blog`
-- AUTO_INCREMENT dla tabeli `comments`
--
ALTER TABLE `comments`
MODIFY `comment_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
MODIFY `comment_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT dla tabeli `post`

View File

@ -79,7 +79,7 @@ if ($sql = $mysqli->prepare("SELECT * FROM user WHERE user_id = 2 "))
<img src=\"$avatar\" class=\"align-text-bottom\">
<p>$username</p>
<a href=\"blog.php\">
<a href=\"https://www.facebook.com/$FB\">
<div class=\"col-md-6\">
<div class=\"fa fa-facebook-official\" style=\"font-size:36px\">
@ -87,7 +87,7 @@ if ($sql = $mysqli->prepare("SELECT * FROM user WHERE user_id = 2 "))
</div> </div> </a>
<a href=\"blog.php\">
<a href=\"https://twitter.com/$TW\">
<div class=\"col-md-6\">
<div class=\"fa fa-twitter-square\" style=\"font-size:36px\"\">
<div class=\"ikona\"><i><p1> $TW </p1></i> </div>

22
blog-post/comment.php Normal file
View File

@ -0,0 +1,22 @@
<?php
include "../settings/db_connect.php";
$_SESSION['message'] = '';
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$tekst = $mysqli->real_escape_string($_POST['tekst']);
$_SESSION['tekst'] = $tekst;
$sql = "INSERT INTO comments (tekst)"
. "Values ('$tekst')";
if($mysqli->query($sql) === true){
$_SESSION['message'] = "Dodanie komentarza się powiodło!";
header("location:post.php");
}
else{
$_SESSION['message'] = "Nie udało się dodać komentarza!";
}
}
?>

View File

@ -20,6 +20,15 @@ h1, h2 {
font-weight: 300;
}
z {
font-size: 19px;
line-height: 2.3;
text-align: left;
left: -3px;
position: relative;
}
post {
font-size: 18px;
@ -68,12 +77,23 @@ post {
letter-spacing: 1px;
}
.name-desc h1 {
font-family: 'Oswald', sans-serif;
font-size: 35px;
line-height: 1;
font-weight: 300;
text-align: center;
margin-top:15px;
}
.name-desc h2 {
font-family: 'Oswald', sans-serif;
font-size: 40px;
font-size: 28px;
line-height: 1.45;
font-weight: 300;
text-align: center;
}
.name-desc h4 {
@ -81,8 +101,12 @@ post {
font-size: 19px;
line-height: 1.45;
font-weight: 300;
text-align: right;
margin-bottom: 30;
text-align: right;
margin-bottom: -50;
position: relative;
top: 0px;
}
.name-desc h5 {
font-family: 'Oswald', sans-serif;
@ -220,3 +244,44 @@ object-fit:none;
.scale-down img{
object-fit:scale-down;
}
/* Ocena gwiazdki */
*{
margin: 0;
padding: 0;
}
.rate {
float: left;
height: 46px;
padding: 0 10px;
}
.rate:not(:checked) > input {
position:absolute;
top:-9999px;
}
.rate:not(:checked) > label {
float:right;
width:1em;
overflow:hidden;
white-space:nowrap;
cursor:pointer;
font-size:30px;
color:#ccc;
}
.rate:not(:checked) > label:before {
content: '★ ';
}
.rate > input:checked ~ label {
color: #f4c741;
}
.rate:not(:checked) > label:hover,
.rate:not(:checked) > label:hover ~ label {
color: #deb217;
}
.rate > input:checked + label:hover,
.rate > input:checked + label:hover ~ label,
.rate > input:checked ~ label:hover,
.rate > input:checked ~ label:hover ~ label,
.rate > label:hover ~ input:checked ~ label {
color: #f4c741;
}

View File

@ -78,10 +78,44 @@ if ($sql = $mysqli->prepare("SELECT * FROM post WHERE post_id = 18"))
</div>
<div class=\"col-lg-12 name-desc\">
<post>$main</post>
<h4>$date</h4>
<post>$main</post>
<br>
</div>
";
<div id=\"particles-js\">
<div class=\"container\">
<form class=\"form\" action=\"rating.php\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">
<div class=\"row registerMain\">
<div class=\"col-lg-12 col-md-12 col-sm-12 col-xs-12 name-desc\">
<h4>$date</h4>
</div><br>
<div class=\"col-lg-6 col-md-6 col-sm-6 col-xs-12 name-desc elementsOnRegisterMain\">
<div class=\"form-group inputmain\">
<div class=\"form-group\">
<div class=\"rate\">
<z>Ocena:</z>
<input type=\"submit\" id=\"star5\" name=\"rating\" value=5 />
<input type=\"submit\" id=\"star4\" name=\"rating\" value=4 />
<input type=\"submit\" id=\"star3\" name=\"rating\" value=3 />
<input type=\"submit\" id=\"star2\" name=\"rating\" value=2 />
<input type=\"submit\" id=\"star1\" name=\"rating\" value=1 />
<label for=\"star5\" title=\"5 gwiazdek\">5 stars</label>
<label for=\"star4\" title=\"4 gwiazdki\">4 stars</label>
<label for=\"star3\" title=\"3 gwiazdki\">3 stars</label>
<label for=\"star2\" title=\"2 gwiazdki\">2 stars</label>
<label for=\"star1\" title=\"1 gwiazdka\">1 star</label>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>";
}
$sql->close();
@ -94,7 +128,7 @@ if ($sql = $mysqli->prepare("SELECT * FROM comments ORDER BY comment_id"))
{
$sql->execute();
$sql->bind_result($comment_id,$post_id,$username,$tekst,$data_dodania, $data_modyfikacji);
echo " <div class=\"name\"> <h1> Komentarze</h1> </div> ";
echo " <div class=\"name-desc\"> <h1> Komentarze</h1> </div> ";
while ($sql->fetch())
{
@ -109,8 +143,33 @@ if ($sql = $mysqli->prepare("SELECT * FROM comments ORDER BY comment_id"))
}
else die( "Błąd w zapytaniu SQL! Sprawdź kod SQL w PhpMyAdmin." );
echo " <div class=\"name\"> <h2> Dodaj komentarz:</h2> </div> ";
echo " <div class=\"name\"> <h2> Dodaj komentarz:</h2> </div>
<div id=\"particles-js\">
<div class=\"container\">
<form class=\"form\" action=\"comment.php\" method=\"post\" enctype=\"multipart/form-data\" autocomplete=\"off\">
<div class=\"row registerMain\">
<div class=\"offset-3 col-6 offset-3 elementsOnRegisterMain\">
<div class=\"form-group inputmain\">
<div class=\"form-group\">
<textarea class=\"form-control\" rows=\"4\" id=\"tekst\" name=\"tekst\" required></textarea>
</div>
</div>
</div>
</div>
<div class=\"row registerFooter\">
<div class=\"offset-3 col-6 offset-3 elementsOnRegisterFooter\">
<div>
<input type=\"submit\" value=\"Dodaj\" name=\"register\" class=\"btn btn-block\" />
</div>
</div>
</div>
</form>
</div>
</div>";
$mysqli->close();
?>

22
blog-post/rating.php Normal file
View File

@ -0,0 +1,22 @@
<?php
include "../settings/db_connect.php";
$_SESSION['message'] = '';
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$rating = $mysqli->real_escape_string($_POST['rating']);
$_SESSION['rating'] = $rating;
$sql = "INSERT INTO rating (rating)"
. "Values ($rating)";
if($mysqli->query($sql) === true){
$_SESSION['message'] = "Dodanie oceny się powiodło!";
header("location:post.php");
}
else{
$_SESSION['message'] = "Nie udało się dodać ooceny!";
}
}
?>