I got some strange problems with my php-code
when I try to output this echo "<div class='button menu' onclick=\"javascript:location.href='$baseURI'\">Menu</div>";
sometimes it don´t load the css, even not the div -tags, just the plain "Menu" string
and it´s always printed before my table -tags
how is this possible?
PHP-Code:
<?php
$root_dir = $_SERVER['PHP_SELF'];
echo "<link rel='stylesheet' href='style.css' type='text/css'>";
if (!isset($_GET['command'])) {
echo "<div class='button' onclick=\"javascript:location.href='$baseURI?command=show'\">Personaldaten anzeigen</div>";
//echo "<div class='button' onclick=\"javascript:location.href='$baseURI?command=new'\">neue Person anlegen</div>";
//echo "<div class='button' onclick=\"javascript:location.href='$baseURI?command=work'\">Personaldaten bearbeiten</div>";
} else {
if ($_GET['command'] == "show") {
openSQL();
$sqlbefehl = 'select * from kontakt';
#mysql_query("SET NAMES 'utf8'");
$ergebnis = #mysql_query($sqlbefehl); // SQL-Befehl an die Datenbank schicken
$spalten = #mysql_num_fields($ergebnis);
echo "<table class='style'>";
echo "<tr>";
for ($i = 0; $i < $spalten; $i++) {
echo "<th class='th'>" . mysql_field_name($ergebnis, $i) . "</th>";
}
echo "</tr>";
while (false != ($row = mysql_fetch_row($ergebnis))) {
echo "<tr>";
for ($i = 0; $i < sizeof($row); $i++) {
echo "<td>$row[$i]</td>";
}
echo "</tr>";
}
echo "</table";
}
echo "<div class='button menu' onclick=\"javascript:location.href='$baseURI'\">Menu</div>";
}
function openSQL()
{
$server = "127.0.0.1";
$user = "root";
$passwort = "";
$db = "schule";
$dblink = #mysql_connect($server, $user, $passwort);
if (!#mysql_select_db($db)) {
echo "<br>Keine Verbindung zur Datenbank $db möglich!";
echo "<br>" . mysql_error();
die();
}
}
?>
CSS-Code:
body{
font-family: Verdana;
color: #fff;
background-color: #000;
}
.style{
border-collapse: collapse;
text-align: center;
}
.style table,.style th,.style td {
border: 1px solid white;
}
.style td {
overflow: hidden;
font-size: 12px;
}
.button{
height: 68px;
width: 200px;
border: 3px orange solid;
margin-left: auto;
margin-right: auto;
text-align: center;
border-radius: 5px;
vertical-align: center;
font-size: 24px;
margin-top: 15px;
background-color: #000;
}
.menu{
height: 36px;
width: 75px;
}
.delBtn{
height: 36px;
width: 95px;
}
.del{
background-image: url(del.png);
background-repeat: no-repeat;
width:24px;
height: 24px;
background-size: 25px 25px;
}
.edit{
background-image: url(edit.png);
background-repeat: no-repeat;
background-position: center;
width:24px;
height: 24px;
background-size: 40px 40px;
}
So Im answering my own Question. It was the missing ">" at the closing table-tag. Since I fixed the missing character, the code now work properly.
Thanks for all of your effort <3
Related
I have a problem. I created this code that shows products from my database like products:
<?php
include("connect.php");
session_start();
$status="";
if (isset($_POST['id']) && $_POST['id']!="")
{
$Id = $_POST['id'];
$result = mysqli_query($conn,"SELECT * FROM Producten WHERE `Id`='$Id'");
$row = mysqli_fetch_assoc($result);
$naam = $row['Naam'];
$id = $row['Id'];
$prijs = $row['Prijs'];
$foto = $row['Foto'];
$winkelwagen_array = array(
$id=>array(
'id'=>$id,
'naam'=>$naam,
'prijs'=>$prijs,
'hoeveelheid'=>1,
'foto'=>$foto)
);
if(empty($_SESSION["winkelwagen"]))
{
$_SESSION["winkelwagen"] = $winkelwagen_array;
$status = "<div class='box'>Product toegevoegd aan winkelwagen!</div>";
}
else
{
$_SESSION["winkelwagen"] = array_merge($_SESSION["winkelwagen"],$winkelwagen_array);
$status = "<div class='box'>Product toegevoegd aan winkelwagen!</div>";
}
}
?>
<html>
<head>
<link rel='stylesheet' href='css/style.css' type='text/css' media='all' />
</head>
<body>
<div style="width:700px; margin:50 auto;">
<?php
if(!empty($_SESSION["winkelwagen"]))
{
$winkelwagen_hoeveelheid = count(array_keys($_SESSION["winkelwagen"]));
?>
<div class="winkelwagen_div">
<img src="media/winkelwagen_logo.png" /> Winkelwagen<span><?php echo $winkelwagen_hoeveelheid; ?></span>
</div>
<?php
}
$result = mysqli_query($conn,"SELECT * FROM Producten");
while($row = mysqli_fetch_assoc($result))
{
echo "<div class='product_vak'>
<form method='post' actie=''>
<input type='hidden' name='id' value=".$row['Id']." />
<div class='foto'><img src='".$row['Foto']."' /></div>
<div class='naam'>".$row['Naam']."</div>
<div class='prijs'>€".$row['Prijs']."</div>
<button type='submit' class='koop'>Koop nu</button>
</form>
</div>";
}
mysqli_close($conn);
?>
<div style="clear:both;"></div>
<div class="melding_box" style="margin:10px 0px;">
<?php echo $status; ?>
</div>
</div>
</body>
</html>
with this css:
.product_vak {
float:left;
padding: 10px;
text-align: center;
}
.product_vak:hover {
box-shadow: 0 0 0 2px #e5e5e5;
cursor:pointer;
}
.product_vak .naam {
font-weight:bold;
}
.product_vak .koop {
text-transform: uppercase;
background: #F68B1E;
border: 1px solid #F68B1E;
cursor: pointer;
color: #fff;
padding: 8px 40px;
margin-top: 10px;
}
.product_vak .koop:hover {
background: #f17e0a;
border-color: #f17e0a;
}
.melding_box .box{
margin: 10px 0px;
border: 1px solid #2b772e;
text-align: center;
font-weight: bold;
color: #2b772e;
}
.table td {
border-bottom: #F0F0F0 1px solid;
padding: 10px;
}
.winkelwagen_div {
float:right;
font-weight:bold;
position:relative;
}
.winkelwagen_div a {
color:#000;
}
.winkelwagen_div span {
font-size: 12px;
line-height: 14px;
background: #F68B1E;
padding: 2px;
border: 2px solid #fff;
border-radius: 50%;
position: absolute;
top: -1px;
left: 13px;
color: #fff;
width: 14px;
height: 13px;
text-align: center;
}
.winkelwagen .verwijderen {
background: none;
border: none;
color: #0067ab;
cursor: pointer;
padding: 0px;
}
.winkelwagen .verwijderen:hover {
text-decoration:underline;
}
But when I load the page I see 2 products above each other in a very very large size. Now how can I get them to load next to each other and in a smaller size, because now they are filling the whole screen per product!
I already tried giving product_vak a width, but the image doesn't size with that!
How can I fix this?
try like this
.product_vak {
float:left;
padding: 10px;
text-align: center;
width:40%;
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"
I have a script that checks for dupe values in db and loops through the result and echoes the value using json. However, it is only displaying 1 record instead of 3 which is being sent to php. I would be grateful if someone could point out my error. Thanks
$boxitems = mysqli_real_escape_string($conn, $_POST['box']);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$sql = "SELECT item FROM act WHERE item = '".$boxes."' GROUP BY item HAVING COUNT(*) > 1";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['item'];
}
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($data) . ' already exists. Please enter a unique box reference.';
echo '</div>';
exit;
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.';
echo '</div>';
exit;
}
}
UPDATED screen shot
Put what your want to echo into a single variable that is declared outside the foreach and concatenate each div (one for each loop your foreach does). And then echo it after the loop.
$boxitems = $_POST['box'];
$insertedItems = array();
$duplicateItems = array();
foreach ($boxitems as $boxes) {
$escapedBoxes = mysqli_real_escape_string($conn, $boxes);
$sql = "SELECT item FROM act WHERE item = '".$escapedBoxes."' GROUP BY item HAVING COUNT(*) > 0";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$duplicateItems[] = $row['item'];
}
}
else
{
$insertedItems[] = $escapedBoxes;
}
}
if(!empty($duplicateItems)) {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($duplicateItems) . ' already exists. Please enter a unique box reference.';
echo '</div>';
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.<br/>';
echo json_encode($insertedItems) . ' has been entered successfully into the database.';
echo '</div>';
}
EDIT: Updated code considering u_mulder comment.
$boxitems = mysqli_real_escape_string($conn, $_POST['box']);
$array = array();
$array = $boxitems;
foreach ($array as $boxes) {
$sql = "SELECT item FROM act WHERE item = '".$boxes."' GROUP BY item HAVING COUNT(*) > 1";
$result = mysqli_query($conn, $sql) or die('Error selecting item: ' . mysqli_error());
$num_rows = mysqli_num_rows($result);
if($num_rows) {
while ($row = mysqli_fetch_array($result)) {
$data[] = $row['item'];
}
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: red; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo json_encode($data) . ' already exists. Please enter a unique box reference.';
echo '</div>';
exit;
} else {
echo '<div style="width: 50%; margin-bottom: 20px; border-radius: 5px; border: 1px solid black; background: #63c84c; font-size: 16px; color: white; height: 50px; padding: 15px; line-height: 1.3;">';
echo 'No dupes found in database.';
echo '</div>';
}
exit;
}
An exit inside any function, loop or condition will make the program to go out of it and continue, so it's not iterating through, it's exiting after the first iteration.
With these codes below i create 6 <div> that arrange in 2 columns and 3 rows,and then call custom function writeMsg() that return a div inside each of 6 <div>,but the output has problem.
Thanks for your help.
php codes
<?php
function writeMsg() {
$tab ="<div class='functiontest'>";
echo "test";
$tab .="</div>";
return $tab;
}
$test = writeMsg();
echo "<div class='wrapper'>";
for( $i=0; $i < 6; $i++ ){
echo "<div>" . $test . "</div>";
}
echo "</div>";
?>
css
.functiontest{
width:200px;
height:200px;
display:block;
background-color:#F4F5BD;
float:left;
}
.wrapper{
background-color:#F7ABAC;
display:block;
width:1000px;
min-height:1000px;
float:none;
clear:both;
box-sizing:border-box;
}
.wrapper div{
width:330px;
height:300px;
border:1px solid black;
float:left;
margin-left:7px;
margin-bottom:10px;
display: block;
background:#cccccc;
text-align: center;
}
.wrapper div:nth-child(2n+1){
clear:left;
}
<?php
function writeMsg() {
$tab ="<div class='functiontest'>";
$tab .= "test";
$tab .="</div>";
return $tab;
}
$test = writeMsg();
echo "<div class='wrapper'>";
for( $i=0; $i < 6; $i++ ){
echo "<div>" . $test . "</div>";
}
echo "</div>";
?>
change css to
<style>
.wrapper div.functiontest{
width:200px;
height:200px;
display:block;
background-color:#F4F5BD;
float:left;
}
.wrapper{
background-color:#F7ABAC;
display:block;
width:1000px;
min-height:1000px;
float:none;
clear:both;
box-sizing:border-box;
}
.wrapper div{
width:330px;
height:300px;
border:1px solid black;
float:left;
margin-left:7px;
margin-bottom:10px;
display: block;
background:#cccccc;
text-align: center;
}
.wrapper div:nth-child(2n+1){
clear:left;
}
</style>
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>