add div class inside php if return - php

here is the code i use and i will add a div class for return online and offline , have try it from examples on this site but get error in script
if ($entry['User']['user_id'] > 0)
{
$db = JFactory::getDbo();
$query = sprintf('
SELECT s.userid
FROM #__session AS s
WHERE s.guest = 0 AND s.userid = %d
LIMIT 1', $entry['User']['user_id']);
$userid = $db->setQuery($query)->loadResult();
if ($userid) {
return "Online";
}
}
return "Offline";
here is css off div class online and offline ;
.online {
position: absolute;
top: -4px;
right: -6px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #39b54a;
border: 2px solid #fff;
}
.offline {
position: absolute;
top: -4px;
right: -6px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: #39b54a;
border: 2px solid #fff;
}
i try this but get error :
if ($entry['User']['user_id'] > 0)
{
$db = JFactory::getDbo();
$query = sprintf('
SELECT s.userid
FROM #__session AS s
WHERE s.guest = 0 AND s.userid = %d
LIMIT 1', $entry['User']['user_id']);
$userid = $db->setQuery($query)->loadResult();
<div class=online>
if ($userid) {
return "Online";
}</div>
}
<div class=offline>
return "Offline";
</div>

Change this mess
<div class=online>
if ($userid) {
return "Online";
}</div>
}
<div class=offline>
return "Offline";</div>
Into something like this
if ($userid) {
return "<div class=online>Online</div>";
}
}
return "<div class=offline>Offline</div>";

Related

Trouble inserting a CSS Grid into a flexbox layout

I am trying to insert a CSS grid layout within a flexbox layout so that 3 "grids" flex across a page row then the next three "grids" fill another row etc. At the moment all the "grids" line up in the centre of the page in one column when they should flex into rows of three abreast.
php code for itinery list page
<?php
include("assets/includes/header.inc.php");
include("config.php");
include("classes/ItineryResultsProvider.php");
if(isset($_GET['location'])) {
$location = $_GET['location'];
}
else {
exit("You must select an itinery location");
}
$page = isset($_GET["page"]) ? $_GET["page"] : 1;
?>
<body>
<section class="PageWrapper">
<section class='PageContentContainer'>
<?php
$resultsProvider = new ItineryListProvider($conn);
$pageSize = 18;
$numResults = $resultsProvider->getNumResultsItineryList($location);
$removeUnderscoreLocation = str_replace('_', ' ', $location);
echo "<div class='PageContentListCount'>
<h2>This page shows a list of $numResults suggested itineries for $removeUnderscoreLocation.</h2>
</div>";
echo $resultsProvider->getResultsItineryList($page, $pageSize, $location)
?>
<div class="PaginationGridContainer">
<div class="PaginationGridLogo">
<img src="assets/logos/Page_Numbering.png">
</div>
<div class="PaginationGridNumbering">
<?php
$pagesToShow = 10;
$numPages = ceil($numResults / $pageSize);
$pagesLeft = min($pagesToShow, $numPages);
$currentPage = $page - floor($pagesToShow / 2);
if($currentPage < 1) {
$currentPage = 1;
}
if($currentPage + $pagesLeft > $numPages + 1) {
$currentPage = $numPages + 1 - $pagesLeft;
}
while($pagesLeft != 0 && $currentPage <= $numPages) {
if($currentPage == $page) {
echo "<div class='PageNumberContainer'>
<span class='PageNumber'>$currentPage</span>
</div>";
}
else {
echo "<div class='PageNumberContainer'>
<a href='ItineryList.php?location=$location&page=$currentPage'>
<span class='PageNumber'>$currentPage</span>
</a>
</div>";
}
$currentPage++;
$pagesLeft--;
}
?>
</div>
</div>
</section>
</section>
</body>
</html>
php code for itinery list page classes
<?php
class ItineryListProvider {
private $conn;
public function __construct($conn) {
$this->conn = $conn;
}
public function getNumResultsItineryList($location) {
$query = $this->conn->prepare("SELECT COUNT(*) as total
FROM bth_itn_tbl WHERE ITN_STATUS='1'
AND ITN_LOCATION LIKE :location");
$searchTerm = $location;
$query->bindParam(":location", $searchTerm);
$query->execute();
$row = $query->fetch(PDO::FETCH_ASSOC);
return $row["total"];
}
public function getResultsItineryList($page, $pageSize, $location) {
$fromLimit = ($page - 1) * $pageSize;
$query = $this->conn->prepare("SELECT *
FROM bth_itn_tbl WHERE ITN_STATUS='1'
AND ITN_LOCATION LIKE :location
ORDER BY ITN_CLICK_COUNT DESC
LIMIT :fromLimit, :pageSize");
$searchTerm = $location;
$query->bindParam(":location", $searchTerm);
$query->bindParam(":fromLimit", $fromLimit, PDO::PARAM_INT);
$query->bindParam(":pageSize", $pageSize, PDO::PARAM_INT);
$query->execute();
$resultsItineryList = "<div>";
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$id = $row["ITN_KEY"];
$itnImg = $row["ITN_IMG_PATH"];
$title = $row["ITN_TITLE"];
$resultsItineryList .= "<div class='ItineryListFlexbox'>
<div class='ItineryListGrid'>
<a class='IntineryListGridImage'>
<img src='$itnImg' height='169' width='225'>
</a>
<a class='ItineryListGridTitle'>$title</a>
</div>
</div>";
}
$resultsItineryList .= "</div>";
return $resultsItineryList;
}
}
?>
CSS code. Note that the PageWrapper and PageContentContainer is generic for all pages and works fine. The issue is with the ItineryListGrid which is supposed to flex within ItineryListFlexbox. At the moment it is a vertical centred column within the PageContentContainer
.PageWrapper {
padding-top: 100px;
margin-bottom: 20px;
width: 100%;
display: flex;
justify-content: center;
flex-flow: row;
}
.PageContentContainer {
float: left;
margin: 0px 5px 5px 5px;
width: 710px;
border: 2px solid #111;
border-radius: 4px;
box-shadow: 6px 6px 4px #888888;
}
.PageContentListCount h2 {
margin: 20px 10px 20px 10px;
margin-left: 10px;
font-family: Catamaran;
font-size: 25px;
line-height: 30px;
font-weight: 900;
color: #111;
justify-content: left;
}
.PageContentContainer h3 {
margin: 0 0 15px 10px;
font-family: Catamaran;
font-size: 18px;
font-weight: 900;
color: #111;
}
.AdvertisingContainer {
float: right;
margin: 0px 15px 5px 5px;
width: 320px;
border: 2px solid #111;
border-radius: 4px;
box-shadow: 6px 6px 4px #888888;
height: auto;
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: auto;
}
.ItineryListFlexbox {
display: flex;
flex-flow: row wrap;
justify-content: center;
height: auto;
}
.ItineryListGrid {
margin: 10px;
display:grid;
grid-template-columns: 225px;
grid-template-rows: 169px 50px;
grid-template-areas:
"IntineryListGridImage"
"ItineryListGridTitle";
}
.IntineryListGridImage {
grid-area: IntineryListGridImage;
}
.ItineryListGridTitle {
grid-area: ItineryListGridTitle;
text-align: left;
margin: 5px 0 5px 0;
text-decoration: none;
font-family: Catamaran;
font-size: 18px;
line-height: 20px;
font-weight: 900;
text-align: center;
color: #111;
}

How could I move my comments while keeping replies underneath?

I’m trying to create a comment system where users can leave comments and then other users can reply to those comments. I want the actual post to be positioned on the left side of the page and comments on the right side so the user won’t have to scroll past the actual post to read comments. I’ve tried using position: absolute, but then that messes with my replying system. Does anyone know a simpler way to do this?
My Code
while ($commentrow = mysqli_fetch_assoc($commentresult)) {
if (mysqli_num_rows($commentresult)==0) {
echo '';
}
else {
$commenterid = $commentrow['userid'];
$commentersql = "SELECT * FROM users WHERE userid = '$commenterid'";
$commenterresult = mysqli_query($conn, $commentersql);
while ($commenterrow = mysqli_fetch_assoc($commenterresult)) {
echo '<div class="PostComments">';
if ($commenterrow['profileimg'] == 1) {
$filename = "profilepics/profile".$commenterid."*";
$fileinfo = glob($filename);
$fileext = explode(".", $fileinfo[0]);
$fileactualext = $fileext[1];
echo "<div class='CommentProfilePicture'><img src='profilepics/profile".$commenterid.".".$fileactualext."?".mt_rand()."'></div>";
}
else {
echo "<div class='CommentProfilePicture'><img src='profilepics/noUser.png'></div>";
}
echo "<div class='CommentUserName'>".$commenterrow['userName']."</div>";
echo "<div class='CommenterComment'>".$commentrow['comment']."</div> </div>";
}
$currentcommentid = $commentrow['commentid'];
$replysql = "SELECT * FROM posts WHERE hostid = '$hostid' AND postid = '$postid' AND commentid = '$currentcommentid' AND replyid > 0";
$replyresult = mysqli_query($conn, $replysql);
while ($replyrow = mysqli_fetch_assoc($replyresult)) {
if (mysqli_num_rows($replyresult)==0) {
echo '';
}
else {
echo '
<div class="PostReplies">
<p>
'.$replyrow['reply'].'
</p>
</div>
';
}
}
}
}
My Styling
.PostPage {
width: 60%;
padding: 10px;
background-color: #555;
color: white;
margin: 0px;
}
.PostComments {
width: 30%;
background-color: #555;
padding: 10px;
border-radius: 4px;
color: white;
}
.PostReplies {
width: 30%;
background-color: #555;
padding: 10px;
color: white;
}
If you have any questions I will be more than happy to answer them.
Create a div tag over the comments and replies.

Simulate a4 page in html PHP LOOP

I want to create a loop that when it reaches 20th, just create a new page, then, again a new page and so until the cycle is done.
I have 5rows 4 columns (5x4 = 20 labels per page)
The peculiarity is that I have four prices and the number of labels depends on the total number. I give an example.
I have columns broi, price1, price2, price3, price4
With sample data:
broi: 90
price1: 4.85
price2: 7.90
price3: 9.30
price4: 11.10
We divide (broi)90/4 and we get that from 1 price we have to have 22.5, for example:
price1: 4,85 - 22pcs
price2: 7.90 - 24pcs
price3: 9.30 - 22pcs
price4: 11.10 - 22pcs
(total pcs 90 = broi)
Here's an example, by way of a snapshot,
And I want to be:
My php code is:
<?php
$mysqli = new mysqli('localhost', 'user', 'pass', 'db');
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$mysqli->set_charset("utf8");
/* разделяме на 4 и правиме второто число да компенсира остатъка */
function calculate_columns(int $total, int $size, int $prefer = 1): array {
$columns = [];
for ($i = 0; $i < $size; $i++) {
$columns[$i] = floor($total / $size);
}
$columns[$prefer] += $total - $columns[$prefer] * $size;
return $columns;
/*
Array (
[0] => 22
[1] => 24
[2] => 22
[3] => 22
)
*/
}
?><html>
<head>
<style>body {
background: rgb(204,204,204);
}
page {
background: white;
display: block;
margin: 0 auto;
margin-bottom: 0.5cm;
//box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
}
page[size="A4"] {
width: 21cm;
height: 29.7cm;
}
page[size="A4"][layout="landscape"] {
width: 29.7cm;
height: 21cm;
}
page[size="A3"] {
width: 29.7cm;
height: 42cm;
}
page[size="A3"][layout="landscape"] {
width: 42cm;
height: 29.7cm;
}
page[size="A5"] {
width: 14.8cm;
height: 21cm;
}
page[size="A5"][layout="landscape"] {
width: 21cm;
height: 14.8cm;
}
#media print {
body, page {
margin: 0;
box-shadow: 0;
}
}
/* Container holding the image and the text */
.container {
position: relative;
text-align: center;
margin-left:10px;
color: #000 ;
font-size:19px !important;
font-weight: bold; font: arial;
}
/* Centered text */
.centered {
position: absolute;
top: 70%;
left: 50%;
transform: translate(-50%, -50%);
margin-left:6px;
}
.A4 {
background: white;
width: 21cm;
height: 29.7cm;
display: block;
margin: 0 auto;
padding: 10px 25px;
margin-bottom: 0.5cm;
box-shadow: 0 0 0.5cm rgba(0, 0, 0, 0.5);
overflow-y: scroll;
box-sizing: border-box;
font-size: 12pt;
}
#media print {
.page-break {
display: block;
page-break-before: always;
}
size: A4 portrait;
}
#media print {
body {
margin: 0;
padding: 0;
}
.A4 {
box-shadow: none;
margin: 0;
width: auto;
height: auto;
}
.noprint {
display: none;
}
.enable-print {
display: block;
}
}
</style>
<script>
//window.print();
</script>
</head>
<body>
<?php
$lstoutput = array();
$sqlquery = $mysqli->query("SELECT * FROM items WHERE id=1");
while($row = $sqlquery->fetch_array()) {
$lstoutput[] = $row;
}
$labels = calculate_columns($lstoutput[0]['broi'], 4);
$page_much = $lstoutput[0]['broi']/20; //$labels[0]
$page_number = '0';
for(; $page_number < $page_much ; $page_number++){
echo '<page size="A4"><table cellpadding="6" style="padding-top: 30px"><tbody>';
if($lstoutput[0]['price1'] != null) {
$labels_number = 0;
for ($labels_number = 0; $labels_number <= $labels[0]; $labels_number++) {
if ($labels_number %4 === 0) {
echo("</tr>\n<tr style='margin:1px'>");
}
echo '<td style="margin:1px" class="container"><img src="label.png" alt="label" style="border:1px solid #333;width:184px;height:184px" /><div class="centered">'.$lstoutput[0]['price1'].'</div></td>';
}
}
if($lstoutput[0]['price2'] != null) {
$labels_number = 0;
for ($labels_number = 0; $labels_number <= $labels[0]; $labels_number++) {
if ($labels_number %4 === 0) {
echo("</tr>\n<tr style='margin:1px'>");
}
echo '<td style="margin:1px" class="container"><img src="label.png" alt="label" style="border:1px solid #333;width:184px;height:184px" /><div class="centered">'.$lstoutput[0]['price2'].'</div></td>';
}
}
echo '</tbody></table></page>';
}
?>
</body>
</html>
If you set the labels as divs with css display: inline-block instead of using a table, the browser itself will reflow the elements to fit on each page.
.label {
display: inline-block;
width: 200px;
height: 100px;
border: 1px solid black;
padding: 5px;
margin: 5px;
}
<div class="label">label</div>
<div class="label">label</div>
<div class="label">label</div>
<div class="label">label</div>
<div class="label">label</div>
...
This looks as this in my preview window:
#DinoCoderSaurus I set the code after I removed the cycle to create the number of pages, added the page-break-after function (css) but did not get it again, set the photo + code.
table { page-break-inside:auto }
tr { page-break-inside:avoid; page-break-after:auto }
<?php
$mysqli = new mysqli('localhost', 'USER', 'PASS', 'DATABASE');
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$mysqli->set_charset("utf8");
/* разделяме на 4 и правиме второто число да компенсира остатъка */
function calculate_columns(int $total, int $size, int $prefer = 1): array {
$columns = [];
for ($i = 0; $i < $size; $i++) {
$columns[$i] = floor($total / $size);
}
$columns[$prefer] += $total - $columns[$prefer] * $size;
return $columns;
/*
Array (
[0] => 22
[1] => 24
[2] => 22
[3] => 22
)
*/
}
?><html>
<head>
<style>body {
background: rgb(204,204,204);
}
page {
background: white;
display: block;
margin: 0 auto;
margin-bottom: 0.5cm;
//box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
}
page[size="A4"] {
width: 21cm;
height: 29.7cm;
}
page[size="A4"][layout="landscape"] {
width: 29.7cm;
height: 21cm;
}
page[size="A3"] {
width: 29.7cm;
height: 42cm;
}
page[size="A3"][layout="landscape"] {
width: 42cm;
height: 29.7cm;
}
page[size="A5"] {
width: 14.8cm;
height: 21cm;
}
page[size="A5"][layout="landscape"] {
width: 21cm;
height: 14.8cm;
}
#media print {
body, page {
margin: 0;
box-shadow: 0;
}
}
/* Container holding the image and the text */
.container {
position: relative;
text-align: center;
margin-left:10px;
color: #000 ;
font-size:19px !important;
font-weight: bold; font: arial;
}
/* Centered text */
.centered {
position: absolute;
top: 70%;
left: 50%;
transform: translate(-50%, -50%);
margin-left:6px;
}
.A4 {
background: white;
width: 21cm;
height: 29.7cm;
display: block;
margin: 0 auto;
padding: 10px 25px;
margin-bottom: 0.5cm;
box-shadow: 0 0 0.5cm rgba(0, 0, 0, 0.5);
overflow-y: scroll;
box-sizing: border-box;
font-size: 12pt;
}
#media print {
.page-break {
display: block;
page-break-before: always;
}
size: A4 portrait;
}
#media print {
body {
margin: 0;
padding: 0;
}
.A4 {
box-shadow: none;
margin: 0;
width: auto;
height: auto;
}
.noprint {
display: none;
}
.enable-print {
display: block;
}
}
table { page-break-inside:auto }
tr { page-break-inside:avoid; page-break-after:auto }
</style>
<script>
//window.print();
</script>
</head>
<body>
<?php
$lstoutput = array();
$sqlquery = $mysqli->query("SELECT * FROM items WHERE id=1");
while($row = $sqlquery->fetch_array()) {
$lstoutput[] = $row;
}
$labels = calculate_columns($lstoutput[0]['broi'], 4);
echo '<page size="A4"><table cellpadding="5" style="padding-top: 10px"><tbody>';
if($lstoutput[0]['price1'] != null) {
$labels_number = 0;
for ($labels_number = 0; $labels_number <= $labels[0]; $labels_number++) {
if ($labels_number %4 === 0) {
echo("</tr>\n<tr style='margin:1px'>");
}
echo '<td style="margin:1px" class="container"><img src="label.png" alt="label" style="border:1px solid #000;width:90%;height:90%" /><div class="centered">'.$lstoutput[0]['price1'].'</div></td>';
}
}
if($lstoutput[0]['price2'] != null) {
$labels_number = 0;
for ($labels_number = 0; $labels_number <= $labels[1]; $labels_number++) {
if ($labels_number %4 === 0) {
echo("</tr>\n<tr style='margin:1px'>");
}
echo '<td style="margin:1px" class="container"><img src="label.png" alt="label" style="border:1px solid #000;width:90%;height:90%" /><div class="centered">'.$lstoutput[0]['price2'].'</div></td>';
}
}
echo '</tbody></table></page>';
?>
</body>
</html>

While loop only showing 1 result

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.

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