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

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;

Related

PHP/HTML: How I could change my image source depending on the value from the database

I have HTML in my PHP file, because I'm using data from a database to display on my website. (This is my first time using PHP so my knowledge is really little)
My question is how I could change my image source depending on the value from the database.
The depending value I'm talking about is called = SENT_NUMBER_1
<?php
//This line will make the page auto-refresh each 15 seconds
$page = $_SERVER['PHP_SELF'];
$sec = "15";?>
<html>
<head>
<style>
div.image{
transform: rotate(90deg);
width:100px;
height:200px;
background: transparent;
position: absolute;
top:30%;
bottom: 0;
left: 0;
right: 0;
margin: auto;
content:url(photo) // This is the url I'm wanting to change into either: Empty.png / 25.png / 50.png / 75.png /100.png || like = content:url(/50.png)
}
</style>
<div class="image"></div>
i also have something like this but I don't know if this works, and where to put it.
if(SENT_NUMBER_1 <= 10){
photo = "10.png"
}
elseif(SENT_NUMBER_1 >= 11 && <=25){
photo = "25.png"
}
elseif(SENT_NUMBER_1 >= 26 && <=49){
photo = "50.png"
}
elseif(SENT_NUMBER_1 >= 50 && <=74){
photo = "75.png"
}
elseif(SENT_NUMBER_1 >= 75 && <=100){
photo = "100.png"
}
Here is a screenshot from the [website], the image I'm wanting to change is the battery you see on the screenshot.
Whole code for if I missed something
<?php
//This line will make the page auto-refresh each 15 seconds
$page = $_SERVER['PHP_SELF'];
$sec = "15";
?>
<html>
<head>
<link rel="shortcut icon" href="/favicon-16x16.ico" type="image/x-icon">
<title>Rattengifmelder</title>
<style>
#font-face {
font-family: Asket Extended; src: url('AsketExtended-Light.otf');
font-family: Asket Extended; font-weight: bold; src: url('AsketExtended-Light.otf');
}
body{
height: 200vh;
}
tbody{
text-align: center;
}
td{
background-color: transparent;
width: 70px;
height: 70px;
}
table, th, td{
font-size: 30px;
width: 100px;
margin-left: auto;
margin-right: auto;
background: transparent;
border: 10px solid white;
font-family: 'Asket Extended', sans-serif;
}
div.image{
transform: rotate(90deg);
width:100px;
height:200px;
background: transparent;
position: absolute;
top:30%;
bottom: 0;
left: 0;
right: 0;
margin: auto;
content:url(/100.png)
}
div.image2{
width:100px;
height:200px;
background: transparent;
content:url(/Empty.png)
}
div.image3{
width:100px;
height:200px;
background: transparent;
content:url(/Empty.png)
}
.center{
position: sticky;
top: 0px;
text-align: center;
font-family: 'Asket Extended', sans-serif;
font-size: 50px;
font-weight: bold;
padding-top: 50px;
background-color: white;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
height: 10%;
width: 100%;
background-color: white;
color: white;
text-align: center;
border-top: 1px solid lightgrey ;
}
div.container {
float: left;
margin: 100px;
padding: 20px;
width: 100px;
}
.menu{
position: absolute;
left: 70px;
top: 65px;
width:20px;
height:20px;
content:url(/menu.png)
}
.battery{
position: absolute;
left: 93%;
top: 50px;
width: 30px;
height:60px;
transform: rotate(90deg);
content:url(/100.png)
}
.one{
}
.two{
}
.three{
}
</style>
<!--//I've used bootstrap for the tables, so I inport the CSS files for taht as well...-->
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<?php
include("database_connect.php"); //We include the database_connect.php which has the data for the connection to the database
// Check the connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Again, we grab the table out of the database, name is ESPtable2 in this case
$result = mysqli_query($con,"SELECT * FROM ESPtable2");//table select
//Now we create the table with all the values from the database
//loop through the table and print the data into the table
while($row = mysqli_fetch_array($result)) {
$column1 = "RECEIVED_BOOL1";
$column2 = "RECEIVED_BOOL2";
$column3 = "RECEIVED_BOOL3";
$column4 = "RECEIVED_BOOL4";
$column5 = "RECEIVED_BOOL5";
}
?>
<div class="center">
<div class="menu"></div>
<div class="battery"></div>
<p>Rattengifmelder</p>
</div>
<?php
include("database_connect.php");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM ESPtable2");//table select
echo "<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr class='active'>
<td style='color: grey;'>Grasveld achter</td>
</tr>
";
while($row = mysqli_fetch_array($result)) {
$cur_sent_bool_1 = $row['SENT_BOOL_1'];
$cur_sent_bool_2 = $row['SENT_BOOL_2'];
$cur_sent_bool_3 = $row['SENT_BOOL_3'];
if($cur_sent_bool_1 == 1){
$label_sent_bool_1 = "label-success";
$text_sent_bool_1 = "Actief";
}
else{
$label_sent_bool_1 = "label-danger";
$text_sent_bool_1 = "Inactief";
}
/*echo "<tr class='info'>";
$unit_id = $row['id'];
echo "<td>" . $row['id'] . "</td>"; */
echo "<td>
<span class='label $label_sent_bool_1'>"
. $text_sent_bool_1 . "</td>
</span>";
}
echo "</table>";
?>
<?php
include("database_connect.php");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM ESPtable2");//table select
echo "<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr class='active'>
</tr>
";
while($row = mysqli_fetch_array($result)) {
echo "<tr class='info'>";
echo "<td style='background-color: transparent;'>" . $row['SENT_NUMBER_1'] . "% </td>";
echo "</tr></tbody>";
}
echo "</table>
<br>
";
?>
<div class="footer">
<p></p>
</div>
<div class="image"></div> // this is where the image is displayed
I didn't get where you are getting value of SENT_NUMBER_1 in your php code ??
then
SENT_NUMBER_1 should be $SENT_NUMBER_1
photo should be $photo
if($SENT_NUMBER_1 <= 10){
$photo = "10.png";
}
if($SENT_NUMBER_1 >= 11 && $SENT_NUMBER_1 <=25){
$photo = "25.png";
}
if($SENT_NUMBER_1 >= 26 && $SENT_NUMBER_1 <=49){
$photo = "50.png";
}
if($SENT_NUMBER_1 >= 50 && $SENT_NUMBER_1 <=74){
$photo = "75.png";
}
if($SENT_NUMBER_1 >= 75 && $SENT_NUMBER_1 <=100){
$photo = "100.png";
}
and then
<div class="image"><img src="<?php echo $photo;?>"></div> // this is where the image is displayed
also declare full path of image.
e.g.
$photo = 'imagefolder/100.png';

How to align form and text generated by function?

I'm developing a webpage that has many forms with some text close to form. This form and text are generated by a function, but I get this
As you can see the forms and the text are not aligned with forms and text below. I would like to have this:
(this work because I put spaces manually). This is how I create forms.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo $name;
echo '<input type="text" name="'. $product. '" id="'. $product. '" style="font-size:12pt;height:30px"/> x'.$productp. '€
price:'.$productpt.'€<br>';
}
echo '<form method="post" name="form1" id="form1" autocomplete="off">'; //start form
echo '<div class="leftpane">'; //start leftpane
echo '<h1>';
echo '<font size="6" color="red"> ALIMENTS </font><br>';
//ADD ELEMENTS IN MY MENU
//The first argument is the form name and id, the second is the name that will be printed(to the left of the form), the third argument is the price.
$menu[] = new Menu("pasta", "Pasta", 2);
$menu[] = new Menu("spaghetti", "Spaghetti", 1.50);
$menu[] = new Menu("pizza", "Pizza", 5);
$menu[] = new Menu("chicken_wings_x4", "Chicken Wings X4", 4.50);
$menu[] = new Menu("cheeseburger", "Cheeseburger", 6);
$menu[] = new Menu("Sandwich", "Sandwich", 2);
$menu[] = new Menu("hamburger", "Hamburger", 4.50);
$menu[] = new Menu("stuff", "stuff", 15.50);
//FOR EACH ELEMENT CREATE A FORM
for($i=0; $i<count($menu); $i++){
add_form($menu[$i]->form_name, $menu[$i]->name, $menu[$i]->price);
}
echo '</h1>';
echo '</div>'; //Close leftpane
...Do Others stuff in middlepane and in rightpane
To be clearer in html, for example the first form will be:
<input type="text" name="pasta" id="pasta" style="font-size:12pt;height:30px"/> x2€ price:X€<br>
I thought to divide in 3 parts my leftpane and to place $name to the left, the form to the middle and the price to the right. But the problem is that i create form in function, so I do not know how to do it.
This is my css:
<style>
input[type=text] {
width: 10%;
margin: 7.5px 0;
box-sizing: border-box;
}
input[type=submit].class1 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit].class2 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
margin: 0;
}
.container {
width: 100%;
height: 100%;
}
.leftpane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.middlepane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.rightpane {
width: 33%;
height: 100%;
position: relative;
float: right;
border-collapse: collapse;
}
form {
display: inline-block;
}
h1 {
font-size: 19.5px;
}
</style>
I would suggest you to use a table. https://www.w3schools.com/html/html_tables.asp
Or you could wrap every section into a div-container and define its width.
I think your output code would really benefit from some additional HTML structure with classes that allow you to control their layout in a consistent way with CSS. I would update the add_form() function:
function add_form($product,$name,$productp) {
$productpt = "X";
echo '<div class="form-wrap">';
echo '<span class="form-name">' . $name . '</span>';
echo '<input type="text" name="'. $product. '" id="'. $product. '"/> <span class="form-label">x'.$productp. '€</span> <span class="form-price">price:'.$productpt.'€</span>';
echo '</div>';
}
Then with the output having more targetable HTML structure you can do this with CSS:
.form-wrap input {
font-size: 12pt;
height: 30px
}
.form-name {
display: inline-block;
width: 100px;
margin-right: 20px;
}
.form-label {
display: inline-block;
margin-left: 5px;
margin-right: 20px;
}
<div class="form-wrap">
<span class="form-name">Something</span>
<input type="text" name="something" id="somethingId" />
<span class="form-label">x1€</span>
<span class="form-price">price:1€</span>
</div>
<div class="form-wrap">
<span class="form-name">Another one</span>
<input type="text" name="anotherone" id="somethingId2" />
<span class="form-label">x2€</span>
<span class="form-price">price:2€</span>
</div>
<div class="form-wrap">
<span class="form-name">Number Three</span>
<input type="text" name="thirdone" id="somethingId3" />
<span class="form-label">x3€</span>
<span class="form-price">price:3€</span>
</div>
Try this.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo "<table><tr>";
echo "<td width='20%'>" . $name . "</td>";
echo "<td width='20%'><input type='text' name='". $product . "' id='" . $product . "' style='font-size:12pt;height:30px;' /></td>";
echo "<td width='20%'>x" . $productp . "€</td>";
echo "<td width='20%'>price:" . $productpt . "€</td>";
echo "</tr></table>";
}

why it float left is not working and these codes

my question is that why float left is not working under these codes
when i use them all the result just display on single div and other 7 where showing under that div at same place so please tell me what is the solution of this prob
<div class="tv_l" style="top:1465px;
left:10px;
position:absolute;
width:1690px;
height:10px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
} else {
echo "";
}
?>
<?php
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8" )
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>;
<div class="son_s_p" style="top:1957px;
left:12px;
-webkit-box-shadow:0 3px 8px rgba(0, 0, 0, .25);
position:inherit;
background:white;
width:190px;
height:240px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:center;
float:left;
">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>"style="width:198px; height:148px;" >
<br>
<?php echo $row['name']; ?><br><br>
<div id="son_s_p" style="top:218px;
left:px;
position:absolute;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:justify;">
<?php echo $row['time']; ?> <span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php
}
?>
with using position
without using position data will go top and top do not work
your wrong is that you put in div "float: left;" and thats wrong.you should put before it style attribute and it is Style="float: left;"
correct code is:
<div class="tv_l" style="top:1465px;
left:10px;
position:absolute;
width:1690px;
height:10px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
} else {
echo "";
}
?>
<?php
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8" )
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>;
<div class="son_s_p" style="top:1957px;
left:12px;
-webkit-box-shadow:0 3px 8px rgba(0, 0, 0, .25);
position:inherit;
background:white;
width:190px;
height:240px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:center;
float:left;
">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>"style="width:198px; height:148px;" >
<br>
<?php echo $row['name']; ?><br><br>
<div id="son_s_p" style="top:218px;
left:px;
position:absolute;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:justify;">
<?php echo $row['time']; ?> <span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php
}
?>
Your question was unclear, however I have cleaned up your code so that the div .tv_l is to the left of the div .son_s_p and its content:
.tv_l {
border-radius: 3px/3px;
padding-right: 10px;
border-left: 10px;
border: 1px solid;
float: left;
}
.son_s_p {
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
background: white;
width: 190px;
height: 240px;
border-radius: 3px/3px;
padding-right: 10px;
border-left: 10px;
text-align: center;
float: left;
}
#son_s_p {
border-radius: 3px/3px;
padding-right: 10px;
padding-top: px;
border-left: 10px;
text-align: justify;
}
<div class="tv_l">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}else{
echo "";
}
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8")
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>
<div class="son_s_p">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>" style="width:198px; height:148px;">
<br>
<?php echo $row['name']; ?>
<br>
<br>
<div id="son_s_p">
<?php echo $row['time']; ?>
<span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php } ?>
It looks like you are using absolute positioning on your DIVs. Floats cannot work that way. Use this instead:
position: static;
float: left;
If I were you I would first try to get it to work with pure HTML and CSS with some dummy data, before hooking it up to the database.
Here's an example of how you can achieve floating with divs, in contrast to your approach:
https://jsfiddle.net/19zrr99n/

Delete comment from database 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'.

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