Delete comment from database php - php

I am trying to delete comments from my comment system but the code I have is not working. I want to be able to delete each comment from my table including the parent comments. At the moment my code does not get the parameter of the comment from the delete button link.
function.php:
<?php
function getComments($row) {
echo "<li class='comment'>";
echo "<div class='aut'>" . $row['author'] . "</div>";
echo "<div class='comment-body'>" . $row['comment'] . "</div>";
echo "<div class='timestamp'>" . $row['created_at'] . "</div>";
echo "<a href='#comment_form' class='reply' id='" . $row['id'] . "'>Edit Song</a>";
echo "<span> </span>";
echo "<a href='delete.php?id='" . $row['id'] . "'>Delete Song</a>";
$q = "SELECT * FROM threaded_comments WHERE parent_id = ".$row['id']."";
$r = mysql_query($q);
if(mysql_num_rows($r)>0)
{
echo "<ul>";
while($row = mysql_fetch_assoc($r)) {
getComments($row);
}
echo "</ul>";
}
echo "</li>";
}
?>
delete.php:
<?php
include 'includes/config.php';
$deleteid = $_GET['id'];
mysql_query("DELETE FROM threaded_comments WHERE id='$deleteid'");
echo "Song has been deleted!";
header ('Location: index.php');
?>
I have added the index.php and post_comment page page. Also the delete function still doesn't work when I made the changes.
index.php:
<?php
include("config.php");
include("functions.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Multi-Lyric Collaboration System</title>
<script type='text/javascript' src='jquery.pack.js'></script>
<script type='text/javascript'>
$(function(){
$("a.reply").click(function() {
var id = $(this).attr("id");
$("#parent_id").attr("value", id);
$("#name").focus();
});
});
</script>
<style type='text/css'>
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, blockquote,
pre, form, fieldset, table, th, td { margin: 0; padding: 0; }
body {
font-size: 14px;
line-height:1.3em;
background: url('music.jpg');
height: 100%;
background-size:100% ;
background-position: static;
background-color: purple;
min-height: 100%;
background-repeat: no-repeat;
}
label{
color: white;
font-size: 2em;
}
a, a:visited {
outline:none;
color:#7d5f1e;
}
.clear {
clear:both;
}
#wrapper {
width:480px;
margin:0px auto;
padding:15px 0px;
}
.comment {
padding:5px;
border:2px solid black;
border-width: 1px;
margin-top:15px;
list-style:none;
background-color: white;
opacity: 0.96;
-moz-border-radius:20px;
-webkit-border-radius:20px;
overflow-y: scroll;
}
.aut {
font-weight:bold;
}
.timestamp {
font-size:85%;
float:right;
}
#comment_form {
margin-top:15px;
}
#comment_form input {
font-size:1.2em;
margin:0 0 10px;
padding:3px;
display:block;
width:100%;
}
#comment_body {
display:block;
width:100%;
height:150px;
}
#submit_button {
text-align:center;
clear:both;
}
header{
color: white;
text-align: center;
}
</style>
</head>
<body>
<div id='wrapper'>
<header><font size="20">MultiLyric Collaborator</font></header>
<br>
<ul>
<?php
$q = "SELECT * FROM threaded_comments WHERE parent_id = 0";
$r = mysql_query($q);
while($row = mysql_fetch_assoc($r)):
getComments($row);
endwhile;
?>
</ul>
<form id="comment_form" action="post_comment.php" method='post'>
<label for="name">Name:</label>
<input type="text" name="name" id='name'/>
<label for="comment_body">Enter Song:</label>
<textarea name="comment_body" id='comment_body'></textarea>
<input type='hidden' name='parent_id' id='parent_id' value='0'/>
<div id='submit_button'>
<input type="submit" value="Add comment"/>
</div>
</form>
</div>
</body>
</html>
post_comment.php:
<?php
include("config.php");
$author = mysql_real_escape_string($_POST['name']);
$comment_body = mysql_real_escape_string($_POST['comment_body']);
$parent_id = mysql_real_escape_string($_POST['parent_id']);
$q = "INSERT INTO threaded_comments (author, comment, parent_id) VALUES ('$author', '$comment_body', $parent_id)";
$r = mysql_query($q) or die(mysql_error());
if(mysql_affected_rows()==1) {
header("location:index.php");
}
else {
echo "Comment cannot be posted. Please try again.";
}
?>

From the "SELECT" statement in getComments(), it looks like what you need to do is:
mysql_query("DELETE FROM threaded_comments WHERE parent_id ='$deleteid'");
It is 'parent_id' not 'id'.

Related

Any idea how to stop paragraph from going over its div?

I'm currently trying to make a blog. When I try to make a "preview" of the body of the post. The first post seems to be fine, but the second post goes over its div. I tried changing what tags to use and css formatting but it stays like that.
My code:
HTML
<div class="module">
<div class="blog">
<div class="recents">
<h2>Recent Posts</h2>
<br><br>
<?php
$sql = "select title, body, created_at FROM posts";
$result = mysqli_query($link, $sql);
$query = mysqli_query($link, $sql) or die(mysqli_error($link));
while ($row = mysqli_fetch_assoc($query)) {
$title = $row['title'];
$body = $row['body'];
$created_at = $row['created_at'];
if (strlen($body) > 500) {
$body = substr($body, 0, 500);
}
echo "<h3>" . $title . "</h3><br>";
echo "<p>" . $body . "</p>";
echo "<small>" . $created_at . "</small>";
echo "<br><br>";
}
?>
</div>
<div class="categories">
<h3>Categories</h3>
</div>
</div>
CSS
html {
font-family: 'IBM Plex Serif', serif;
}
.module {
background-color: #fffff7;
box-shadow: 3px 10px 18px #888888;
padding-top: 70px;
padding-left: 130px;
border: 1px solid;
width: 1080px;
margin-left: 380px;
height: 821px;
}
.blog {
display: flex;
flex-direction: row;
text-align: left;
}
.recents {
flex-grow: 2;
width: 570px;
}
.categories {
flex-grow: 1;
}
Any help would be appreciated.
It is because there are no spaces
to fix this try this:
word-wrap: break-word;

How can I make my replies appear as a reply to a comment instead of going to the bottom?

I have a comment system with a reply system and whenever I make a reply to a comment, it appears at the bottom, I must provide all of the code as I am not sure which piece of code is the problem.
I have add this problem for a while, I'm struggling with this problem, and I thank you for helping!
Here is my code for comments.inc.php:
<?php
function setComments($conn) {
if (isset($_POST['commentSubmit'])) {
$uid = $_POST['uid'];
$date = $_POST['date'];
$message = $_POST['message'];
$message = preg_replace (
"/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i",
"\\0",
$message
);
$sql = "INSERT INTO comments (uid, date, message) VALUES ('".mysqli_real_escape_string($conn,$uid)."','".mysqli_real_escape_string($conn,$date)."','".mysqli_real_escape_string($conn,$message)."')";
$result = $conn->query($sql);
}
}
function getComments($conn) {
$sql = "SELECT * FROM comments";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$id = $row['uid'];
$sql2 = "SELECT * FROM users WHERE id='$id'";
$result2 = $conn->query($sql2);
if ($row2 = $result2->fetch_assoc()) {
echo "<div class='comment-box'><p>";
echo $row2['first_name']."<br>";
echo $row['date']."<br>";
echo nl2br($row['message']);
echo "</p>";
if (isset($_SESSION['id'])) {
if ($_SESSION['id'] == $row2['id']) {
echo "<form class='delete-form' method='POST' action='".deleteComments($conn)."'>
<input type='hidden' name='cid' value='".$row['cid']."'>
<button type='submit' name='commentDelete'>Delete</button>
</form>
<form class='edit-form' method='POST' action='editcomment.php'>
<input type='hidden' name='cid' value='".$row['cid']."'>
<input type='hidden' name='uid' value='".$row['uid']."'>
<input type='hidden' name='date' value='".$row['date']."'>
<input type='hidden' name='message' value='".$row['message']."'>
<button>Edit</button>
</form>
";
} else {
echo "<form class='edit-form' method='POST' action='replycomment.php'>
<input type='hidden' name='cid' value='".$row['cid']."'>
<input type='hidden' name='uid' value='".$row['uid']."'>
<input type='hidden' name='date' value='".$row['date']."'>
<input type='hidden' name='reply' value='".$row['reply']."'>
<button style='height: 90px;'><img src='img.ico' style=''></button>
</form>";
}
} else {
echo "<p class='commentmessage'>You need to be logged in to reply</p>";
}
echo "</div>";
}
}
}
function replyComments($conn) {
if (isset($_POST['replySubmit'])) {
$cid = $_POST['cid'];
$uid = $_POST['uid'];
$date = $_POST['date'];
$reply = $_POST['reply'];
$first_name = $_POST['first_name'];
$reply = preg_replace (
"/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i",
"\\0",
$reply
);
$sql = "INSERT INTO replies (uid, first_name, date, reply) VALUES ('".mysqli_real_escape_string($conn,$uid)."','".mysqli_real_escape_string($conn,$first_name)."','".mysqli_real_escape_string($conn,$date)."','".mysqli_real_escape_string($conn,$reply)."')";
$result = $conn->query($sql);
header("Location: index1.php");
}
}
function deleteComments($conn) {
if (isset($_POST['commentDelete'])) {
$cid = $_POST['cid'];
$sql = "DELETE FROM comments WHERE cid='".mysqli_real_escape_string($conn,$cid)."'";
$result = $conn->query($sql);
header("Location: index1.php");
}
}
function editComments($conn) {
if (isset($_POST['commentSubmit'])) {
$cid = mysqli_real_escape_string($conn, $_POST['cid']);
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$date = mysqli_real_escape_string($conn, $_POST['date']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
$sql = "UPDATE comments SET message='".mysqli_real_escape_string($conn,$message)."' WHERE cid='".mysqli_real_escape_string($conn,$cid)."'";
$result = $conn->query($sql);
header("Location: index1.php");
}
}
function getLogin($conn) {
if (isset($_POST['loginSubmit'])) {
$email = $_POST['email'];
$password = md5($_POST['password']);
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
if($row = $result->fetch_assoc()) {
$_SESSION['id'] = $row['id'];
header("Location: index1.php?loginsuccess");
exit();
}
} else {
header("Location: index.php?loginfailed");
exit();
}
}
}
?>
replycomment.php:
<?php
date_default_timezone_set('America/New_York');
include 'dbh.inc.php';
include 'comments.inc.php';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Comments</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
$cid = $_POST['cid'];
$uid = $_POST['uid'];
$date = $_POST['date'];
$reply = $_POST['reply'];
$first_name = $_POST['first_name'];
echo "<form method='POST' action='".replyComments($conn)."'>
<input type='text' name='first_name' placeholder='First Name' value='".$first_name."'>
<br>
<input type='hidden' name='cid' value='".$cid."'>
<input type='hidden' name='uid' value='".$uid."'>
<input type='hidden' name='date' value='".$date."'>
<textarea name='reply'></textarea><br>
<button type='submit' name='replySubmit'>Reply</button>
</form>";
?>
</body>
</html>
index1.php:
<?php
date_default_timezone_set('America/New_York');
include 'dbh.inc.php';
include 'comments.inc.php';
session_start();
$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Comments</title>
</head>
<style>
textarea {
width: 400px;
height: 80px;
background-color: #fff;
resize: none;
margin-left: 2%;
padding: 12px;
font-family: 'Lato', sans-serif;
}
button {
width: 100px;
height: 30px;
background-color: green;
border: none;
color: #fff;
font-weight: 400;
cursor: pointer;
margin-bottom: 60px;
margin-left: %;
font-family: 'Lato', sans-serif;
}
button:hover {
background-color: #282828;
}
.likebtn-wrapper {
margin-bottom: 550%;
}
.comment-box {
width: 845px;
padding: 15px;
margin-bottom: 1%;
background-color: #fff;
border-radius: 4px;
position: relative;
font-family: 'Lato', sans-serif;
}
.comment-box p {
font-size: 16px;
line-height: 20px;
color: gray;
font-weight: 100;
font-family: 'Lato', sans-serif;
padding: 2px 2px;
}
.edit-form {
position: absolute;
top: 0px;
right: 0px;
}
.edit-form button{
width: 40px;
height: 20px;
color: #282828;
background-color: #fff;
opacity: 0.7;
}
.edit-form button:hover{
opacity: 1;
}
.delete-form {
position: absolute;
top: 0px;
right: 60px;
}
.delete-form button{
width: 40px;
height: 20px;
color: #282828;
background-color: #fff;
opacity: 0.7;
}
.delete-form button:hover{
opacity: 1;
}
.reply-form {
float: left;
top: 0px;
right: 120px;
}
.reply-form button{
width: 40px;
height: 20px;
color: #282828;
background-color: #fff;
opacity: 0.7;
}
.reply-form button:hover{
opacity: 1;
}
.commentmessage {
float: right;
position: absolute;
top: 10px;
right: 10px;
font-size: 20px;
}
#myDIV {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: lightblue;
margin-top: 20px;
display: none;
}
html {
margin: 0;
padding: 0;
background-color: #4ebd46;
font-family: 'Montserrat', sans-serif;
}
body {
width: 70%;
margin: 0 auto;
padding: 1em 50px;
background: #feffa6;
font-family: 'Montserrat', sans-serif;
}
.header {
background-color: #87ea6b;
margin: 0;
padding-top: 6%;
padding-bottom: -5%;
margin-top: -2%;
margin-left: -5.2%;
margin-right: -5.2%;
font-family: 'Montserrat', sans-serif;
}
h1, h2 {
text-align: center;
color: white;
font-family: 'Lato', sans-serif;
}
h1 {
font-size: 45px;
margin-left: -18%;
font-family: 'Lato', sans-serif;
}
.logo {
width: 35%;
margin-top: -20%;
}
button {
background-color: #90bd62;
}
.first {
margin-left: 2%;
}
a {
cursor: pointer;
}
.edit-form button{
width: 40px;
height: 20px;
color: #282828;
opacity: 0.7;
margin-left: -60%;
margin-top: 40%;
}
a:hover {
text-decoration: underline;
}
.first {
color: #821510;
font-size: 17px;
}
.replyson {
color: red;
}
.edit-form {
color: red;
}
footer {
padding: 0px;
background-color: #a5dbff;
padding: 10px;
text-align: center;
color: white;
padding-bottom: -20%;
margin-bottom: -2%;
margin-left: -5.2%;
margin-right: -5.2%;
}
.ooter {
padding: 0px;
background-color: #a5dbff;
padding: 20px;
text-align: center;
color: white;
padding-bottom: -50%;
margin-bottom: -2%;
margin-left: 10%;
margin-right: 10%;
}
.term {
color: white;
}
</style>
</head>
<body>
<br>
<br>
<div class="gallery">
<?php
include_once 'lendex.php';
$query = $db->query("SELECT * FROM images ORDER BY id DESC");
if($query->num_rows > 0) {
while($row = $query->fetch_assoc()) {
$imageURL = 'uploads/'.$row['file_name'];
?>
<img src="<?php echo $imageURL; ?>" width='200' height='200' alt=""/>
<?php }
} else { ?>
<p>No image(s) found...</p>
<?php } ?>
</div>
</div>
<div class="first">
<?php
if (isset($_SESSION['id'])) {
echo " <form method='POST' action='".setComments($conn)."'>
<input type='hidden' name='uid' value='".$_SESSION['id']."'>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='message'></textarea><br>
<br>
<button type='submit' name='commentSubmit' style='height: 60px;'>Comment</button>
</form>";
} else {
echo "You need to be logged in to comment!
<br><br>";
}
getComments($conn);
?>
</div>
<?php
$sql = "SELECT * FROM replies;";
$result = mysqli_query($conn,$sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<div class='comment-box'><p>";
echo $row['first_name'];
echo "<br>";
echo $row['date'];
echo "<br>";
echo $row['reply'];
echo "</p>";
echo "</div>";
}
}
?>
</body>
</html>
If you do not anticipate too long threads (otherwise this method will eat your RAM) then you can fetch the comments as a linear list and build the whole hierarchical structure/order of comments in 1 pass - then you will recursively iterate this large array of arrays and your replies will be immediate children of your comments:
$query = 'SELECT id, parent_id, title, body, author, created FROM comments ORDER BY COALESCE(parent_id, 0), id';
$result = $pdo->query($query);
$comments = array();
$refs = array();
while($row = $result->fetch(PDO::FETCH_ASSOC))
{
$thisref = &$refs[$row['id']];
$thisref['title'] = $row['title'];
$thisref['body'] = $row['body'];
$thisref['author'] = $row['author'];
$thisref['created'] = $row['created'];
if($row['parent_id'] == 0) $comments[$row['id']] = &$thisref;
else $refs[$row['parent_id']]['children'] = &$thisref;
}
To better understand the method - take a look at the article "One pass parent-child array structure"

Why does I can't get the title and the note inside each modal?

The while loop works, where I can display each title as a button, and every button has a modal when clicked, but inside each modal, I can't display the title and the note? why?
I once included the up to down inside the while loop execution but I get only the first title and note for every modal.
If anyone has a question on my code, just leave the comment, Please help out with my code :)
<html>
<head>
<script src="jquery-1.10.2.min.js"></script>
<style>
body
{
margin:0;
}
.submitted{
margin:0px;
}
.modal
{
width:100%;
height:100%;
position:fixed;
top:0;
display:none;
}
.modal_close
{
width:100%;
height:100%;
background:rgba(0,0,0,.8);
position:fixed;
top:0;
}
.close
{
cursor:pointer;
}
.padding{
padding:20px 60px 60px 60px;
}
.note{
text-align:center;
}
#note{
font-family: Javanese text;
}
.call_modal{
font-family: myFirstFont;
}
.modal_main
{
width:50%;
height:400px;
background:#fff;
z-index:4;
position:fixed;
top:16%;
border-radius:4px;
left:24%;
display:none;
-webkit-animation-duration: .5s;
-webkit-animation-delay: .0s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-o-animation-fill-mode: both;
-webkit-backface-visibility: visible!important;
-webkit-animation-name: fadeInRight;
}
#-webkit-keyframes fadeInRight{0%{opacity:0;-webkit-transform:translateX(20px)}100%{opacity:1;-webkit-transform:translateX(0)}}
::-webkit-input-placeholder{
font-size: 13.4px;
}
.error{
text-align:center;
padding: 170px; 50px; 50px 50px;
}
button
{
padding:20px;
border-radius:5px;
background:#808080;
border:none;
font-size:18px;
color:#fff;
margin:8%;
}
</style>
<script>
$(document).ready(function(){
$(".call_modal").click(function(){
$(".modal").fadeIn();
$(".modal_main").show();
});
});
$(document).ready(function(){
$(".close").click(function(){
$(".modal").fadeOut();
$(".modal_main").fadeOut();
});
});
$(document).ready(function(){
$(".submitted").click(function(){
$(".modal").fadeOut();
$(".modal_main").fadeOut();
});
});
</script>
</head>
<body>
<?php $con=mysqli_connect("localhost","root","","task");?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<?php
echo ' ';
echo '<button class="call_modal" style="cursor:pointer;">'. $row['title'] . '</button>';
?>
<?php
}?>
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<div class="note"> <?php
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php
echo '<br><br>';
echo '<div class="padding">'.$row['title'].'';
echo '<br><br><br><br>';
echo ''.$row['note'].'</div>';
?>
<img src="i783wQYjrKQ.png" class="close" style="line-height: 12px;
margin-top: 1px;
margin-right: 2px;
position:absolute;
top:0;
right:0;">
</div>
</div>
<?php
}?>
</body>
</html>
It looks like you need some sort of unique identifier for every modal. This is more of a javascript problem, and less of a php problem. I'm adding a data-id to every note, since that seems to be the only thing that needs to be unique. Show the modal, and show the one note relevant.
Try doing something more like this.
echo '<button class="call_modal" data-id="{$row['id']}" style="cursor:pointer;">'. $row['title'] . '</button>';
And this
<div class="modal">
<div class="modal_close close"></div>
<div class="modal_main">
<?php $results = mysqli_query($con, "SELECT * FROM note"); ?>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<div class="note" data-id="<?= $row['id'] ?>">
And this
$(document).ready(function(){
$(".call_modal").click(function(){
$(".modal").fadeIn();
$(".modal .note[data-id='"+$(this).data('id')+"']").show();
});
});

PHP MySQL display data with table rows (clickable)

I have tables that are the publish date of a article and a columns article summary, and those are clickable and should go to a edit page when you click on this. The article should be filled in when you click on it, so you can easy edit the text. I have make the table rows linked but I think I need to take the ID from the tables so it knows what the edit page should be filled in with.
Here is my current code:
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head FROM article";
$result = $conn->query($sql); //it makes the query
?>
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th{
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th{
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
$res=$result->fetch_all(MYSQL_ASSOC); //Splitting all rows in arrays
$keys = array_keys($res[0]); //Arrays getting attached to $keys
// Make the results as rows
echo "<tbody>";
foreach($res as $rows)
{
echo "<tr>";
foreach($rows as $date)
{
echo "<td><a href='bewerkartikel.php'class ='aa'>$date</a>";
echo "</td>";
}
echo "</tr>";
}
echo "</tr>";
}
?>
</section>
</body>
</html>
Add article id to your link ?art_id=some_id
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th {
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th {
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head, art_id FROM article"; //get article id too
$result = $conn->query($sql); //it makes the query
?>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
echo "<tbody>";
while($rows = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>". $rows['art_date'] . "</td>";
echo "<td><a href='bewerkartikel.php?art_id=" . $rows['id'] . "' class ='aa'> " . $rows['art_head'] . "</a>";
echo "</td>";
echo "</tr>";
}
echo "</tr>";
?>
</section>
</body>
</html>
Screenshot
You need to pass the id to next page so what you need to do is add a id to url
like below
"<td><a href='bewerkartikel.php?id=".$date['id']." ' class='aa' >$date</a></td>";
and get the id on bewerkartikel page using
$id = $_GET['id'];
and then you get the particular id to edit.

CSS: Overflow in a DIV horizontally

I'm developing an application that contains a table made ​​by div. The divs are filled according to the results database.
As you can see in the image below.
However, if I put one more item on the bench, just disrupting the entire table. What I would do is to put a rod horizontally so that it could rotate it and so see the other items in the database without messing up the structure.
CODE
CSS
#fundo {
display: block;
height: 550px;
margin-left: -3%;
overflow: scroll;
overflow-y: hidden;
width: 1150px;
}
.vacina, .dose, .aplicacao {
background-color: #D3D3D3;
border-radius: 5px;
float: left;
height: 90px;
margin-top: 6px;
margin-left: 6px;
position: relative;
width: 100px;
}
.vacina {
height: 50px;
}
PHP
include_once ("db.php");
$sql = "SELECT nomeVacina FROM vacina ORDER BY cod";
$ds1=mysql_query($sql);
if ($ds1) {
if (mysql_num_rows($ds1) > 0) {
$x = 0;
///////////////////////////////////////////////
////////////////// DIV VACINA /////////////////
while($linha=mysql_fetch_assoc($ds1)) {
$x++;
if(!($linha['nomeVacina'] == "Outras")) {
echo "<div class='vacina' id='".$x."'>";
echo "<br>".$linha['nomeVacina'];
echo "</div>";
}
}
}
///////////////////////////////////////////////
////////////////// FIM DIV VACINA /////////////
///////////////////////////////////////////////
////////////////// DIV DOSE ///////////////////
for($i = 1; $i < 6; $i++) {
echo "<br><br><br><br><br><br>";
echo "<div class='dose'>";
if($i == 4 || $i == 5) {
echo "<br>Reforco";
}
else {
echo "<br>Dose ".$i;
}
echo "</div>";
///////////////////////////////////////////////
////////////////// FIM DIV DOSE ///////////////
///////////////////////////////////////////////
////////////////// DIV APLICACAO //////////////
$z=0;
for($j = 1; $j <= $x; $j++) {
$sql2 = "SELECT DATE_FORMAT(dataAplicacao, '%d/%m/%Y') AS dataAplicacao, loteVacina, descricaoVacina FROM vacinaaplicada WHERE dose = ".$i." AND codigoVacina = ".$j." AND codPaciente = '".$cns."'";
$ds2=mysql_query($sql2);
$linha2=mysql_fetch_assoc($ds2);
$z++;
echo "<div class='aplicacao' id='".$z.$i."'>";
if($linha2 == "") {
echo "";
}
else {
echo "<div style='margin-top:10px;'>". $linha2['descricaoVacina']."<div class='fonte'><b>Data</b><br></div>". $linha2['dataAplicacao'] . "<div class='fonte'><b>Lote</b><br></div>".$linha2['loteVacina']."</div>" ;
}
echo "</div>";
}
///////////////////////////////////////////////
////////////////// FIM DIV APLICACAO /////////////
}
As you can see in the previous image, has 9 div class Vacina.
If I add a div class Vacina the most, will mess up the table.
What I'd like is to insert more than 9 div class Vacina causing the background div (div class includes all div) increase in width, but leaving it the same way the image, just putting a scroll bar horizontally to display whole div.
If I understood you correctly, I'd try this:
To #fundo, add
white-space: nowrap;
And I replaced float: left; with:
display: inline-block;
Maybe that's what you're looking for.
EDIT:
Okay, I've built an example from scratch (but using javascript, not php, I can't test php atm): JSFiddle.
It's a bit messy but you should be able to code it in PHP if you like to.
Let me know if you've got trouble with this.
EDIT 2:
Just to have it in the answer (not just in its comments), the final solution is: this JSFiddle.
HTML + PHP
<?php
include_once("sessao.php");
if (!isset($_SESSION['funcionario']['cpfFuncionario'])) {
header("Location:index.html");
}
else if($_SESSION['funcionario']['adicionarDireito'] == 0) {
header("Location:funcionario.php");
}
?>
<html>
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<title>Vacina Digital - Cadastrar Vacinação</title>
<script type="text/javascript" src="template/js/script.js"></script>
<link rel="stylesheet" href="template/css/reset.css">
<link rel="stylesheet" href="template/css/fonts.css">
<style>
body {
background-color: #fdfdfd;
overflow-y: auto;
}
#form {
margin-left: 50px;
padding-left: 7%;
padding-top: 50px;
padding-bottom: 10px;
margin-right: 50px;
border: 1px solid #0F935A;
border-radius: 20px;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
#form h1 {
text-align: center;
margin-right: 150px;
font-family: "RobotoCondensed";
font-size: 30px;
}
</style>
</head>
<body>
<?php
include_once 'menufuncionario.php';
?>
<div id="form">
<fieldset>
<?php
include_once("db.php");
if(isset($_POST['cns'])) {
$cns = $_POST['cns'];
$_SESSION['paciente'] = $cns;
}
else{
$cns = $_SESSION['paciente'];
}
$sql = "SELECT *, DATE_FORMAT(dataNascimento, '%d/%m/%Y') AS 'data' FROM populacao WHERE codigoCns = ".$cns;
$ds1=mysql_query($sql);
if ($ds1) {
if (mysql_num_rows($ds1) > 0) {
$sql2 = "SELECT * FROM vacinaaplicada WHERE codPaciente = ".$cns;
$ds2 = mysql_query($sql2);
$linha=mysql_fetch_assoc($ds2);
$linha2=mysql_fetch_assoc($ds1);
$data_nasc = $linha2['data'];
$data_nasc=explode("/",$data_nasc);
$data=date("d/m/Y");
$data=explode("/",$data);
$anos=$data[2]-$data_nasc[2];
if ($data_nasc[1] > $data[1]) {
$anos = $anos-1;
} if ($data_nasc[1] == $data[1]) {
if ($data_nasc[0] <= $data[0]) {
$anos = $anos;
} else {
$anos = $anos-1;
}
} if ($data_nasc[1] < $data[1]) {
$anos = $anos;
}
$data2=date("d/m/Y");
echo "<h1>Carteira de Vacinação - ".$linha2['nomeCrianca']."</h1>";
/*echo "
<div id='caderneta' style='margin-left:-6%'>
";*/
include_once 'caderneta.php';
echo "
</div>";
} else {
echo "<h1>CNS Inválido</h1><br><br>
<center><a href='javascript:window.history.go(-1)'><button style='margin-left:-150px' class='button button-red' href='javascript:window.history.go(-1)'>Voltar</button></a></center>
";
}
}
?>
</div>
</body>
</html>
Caderneta
<html>
<head>
<link rel="stylesheet" href="template/css/fonts.css">
<style type="text/css">
#fundo {
min-width: 800px;
display: block;
overflow: scroll;
overflow-y: hidden;
margin-left: -3%;
height: 550px;
white-space: nowrap;
}
#pinguim, .vacina, .dose, .aplicacao {
width: 100px;
height: 90px;
background-color: #D3D3D3;
margin-top: 6px;
margin-left: 6px;
border-radius: 5px;
position: relative;
float: left;
}
#pinguim, .vacina {
height: 50px;
}
.vacina, .dose{
background: green;
font-family: RobotoCondensed;
font-size: 14pt;
text-align: center;
color: #ffffff;
}
.vacina{
padding-top: -14px;
line-height: 15px;
}
.dose, .aplicacao{
margin-top: -32px;
}
.dose{
line-height: 29px;
}
.aplicacao, .fonte {
font-family: "RobotoLight";
text-align: center;
}
</style>
</head>
<body>
<div id = "fundo">
<div id = "pinguim">
</div>
<?php
include_once ("db.php");
$sql = "SELECT nomeVacina FROM vacina ORDER BY cod";
$ds1=mysql_query($sql);
if ($ds1) {
if (mysql_num_rows($ds1) > 0) {
$x = 0;
$k = 0;
while($linha=mysql_fetch_assoc($ds1)) {
$x++;
if(!($linha['nomeVacina'] == "Outras")) {
echo "<div class='vacina' id='".$x."'>";
echo "<br>".$linha['nomeVacina'];
echo "</div>";
}
}
for($i = 1; $i < 6; $i++) {
echo "<br><br><br><br><br><br>";
echo "<div class='dose'>";
if($i == 4 || $i == 5) {
echo "<br>Reforco";
}
else {
echo "<br>Dose ".$i;
}
echo "</div>";
$z=0;
for($j = 1; $j <= $x; $j++) {
$sql2 = "SELECT DATE_FORMAT(dataAplicacao, '%d/%m/%Y') AS dataAplicacao, loteVacina, descricaoVacina FROM vacinaaplicada WHERE dose = ".$i." AND codigoVacina = ".$j." AND codPaciente = '".$cns."'";
$ds2=mysql_query($sql2);
$linha2=mysql_fetch_assoc($ds2);
$z++;
echo "<div class='aplicacao' id='".$z.$i."'>";
if($linha2 == "") {
echo "";
}
else {
echo "<div style='margin-top:10px;'>". $linha2['descricaoVacina']."<div class='fonte'><b>Data</b><br></div>". $linha2['dataAplicacao'] . "<div class='fonte'><b>Lote</b><br></div>".$linha2['loteVacina']."</div>" ;
}
echo "</div>";
}
}
echo"</div>";
}
}
?>
</div>
</div>
</body>
</html>

Categories