How to set link url through php? - php

I have made 14 url links. I have problem that when I press link 2 it returns 1 and all of the remaining links return decremented to original value. For example when I press 3 it returns 2. When I press 4 it returns 3 and so on. I want to know why is that.This is code
<html>
<body>
<head>
<title>Paging</title>
<style>
#numberDiv
{
display: inline-block;
border: 1px solid black;
width: 35px;
height: 35px;
margin-left: 0.01px;
background-color: aliceblue;
}
</style>
</head>
<?php
if (isset($_GET["id"]))
{
$id=$_GET["id"];
echo $id;
echo "<br>";
}
$a=14;
$b=1;
$c=1;
for ($b = 1; $b <= $a; $b++) {
?><a href="zain.php?id=<?php echo $c; ?>" style="text-decoration: none; text-align: center;color: black;font-size: x-large">
<?php
$c=$b;
echo "<div id='numberDiv'>" . $c . "</div>" ?></a><?php
}
?>
</body>
</html>

Use following code. It will work for you
<html>
<body>
<head>
<title>Paging</title>
<style>
#numberDiv
{
display: inline-block;
border: 1px solid black;
width: 35px;
height: 35px;
margin-left: 0.01px;
background-color: aliceblue;
}
</style>
</head>
<?php
if (isset($_GET["id"]))
{
$id=$_GET["id"];
echo $id;
echo "<br>";
}
$a=14;
$b=1;
$c=1;
for ($b = 1; $b <= $a; $b++) {
$c=$b;
?><a href="zain.php?id=<?php echo $c; ?>" style="text-decoration: none; text-align: center;color: black;font-size: x-large">
<?php
echo "<div id='numberDiv'>" . $c . "</div>" ?></a><?php
}
?>
</body>
</html>

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';

Unwanted space at the top each time I add more tables using php

Can some one help me on why there is a space occuring on the site everytime I add up a table. This is what it looks like at the first table.
Here is the first code where there is no space at the top:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h1 {text-align: left;
border-bottom-style: solid;
border-bottom-color: #1C2833;}
body {
font-family: "American Typewriter",serif;
background-color:#E6D1D9;
}
/*side navigation menu*/
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #49000E;
overflow-x: hidden;
transition: 0.5s;
padding-top: 50px;
}
/* menu links*/
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 15px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover {
color: #F8EDF1 ;
}
.sidenav .closebtn {
position: absolute;
top: 10px;
right: 5px;
font-size: 30px;
margin-left: 50px;
}
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div id="mySidenav" class="sidenav" style="font:5px/15px New Century Schoolbook, TeX Gyre Schola, serif;color:#340D0D">
×
<ul><li>Lab 1: Hello World</li><li>
Lab 2: Basic PHP Script</li><li>
Lab 3: Working with Data Types and Operators</li><li>
Lab 4</li><li>
Lab 6</li><li>
Lab 7</li><li>
Lab 8</li><li>
Lab 9</li><li>
Lab 10</li><li>
Lab 11</li><li>
Lab 12</li><li>
Lab 13</li><li>
Lab 14</li><li>
Lab 15</li><li>
Lab 16</li></ul>
</div>
<?php
define('LABTITLE', 'Laboratory Activity No. 3');
define('DESCRIPTION', 'Working with Data Types and Operators');
?>
<div style ='font:21px/31px New Century Schoolbook, TeX Gyre Schola, serif;color:#7B000B';cursor:pointer" onclick="openNav()">☰ THE LIST OF LABORATORIES </div>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
<?php
echo DESCRIPTION;
$myinteger = 10;
$myfloat = 10.57;
$mystring = "10 apples";
$myboolean = TRUE;
$mynull = NULL;
$myarray = array(1,2,3);
echo "<table border ='.5' width = '1000' cellspacing ='0'>";
// 1
echo '<tr bgcolor = "#E98195"><td><B>1. PHP Data Types </B><br></td></tr>';
echo '<tr><td>1a. $myinteger</td><td>', var_dump($myinteger), '</td></tr>';
echo '<tr><td>1b. $myfloat</td><td>', var_dump($myfloat), '</td></tr>';
echo '<tr><td>1c. $mystring</td><td>', var_dump($mystring), '</td></tr>';
echo '<tr><td>1d. $myboolean</td><td>', var_dump($myboolean), '</td></tr>';
echo '<tr><td>1e. $mynull</td><td>', var_dump($mynull), '</td></tr>';
echo '<tr><td>1f. $myarray</td><td>', var_dump($myarray), '</td></tr>';
echo "</table>";
?>
<title><?php echo LABTITLE; ?></title>
</body>
</html>
and then when I add more tables, there's a space at the top that I don't know how to remove:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h1 {text-align: left;
border-bottom-style: solid;
border-bottom-color: #1C2833;}
body {
font-family: "American Typewriter",serif;
background-color:#E6D1D9;
}
/*side navigation menu*/
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #49000E;
overflow-x: hidden;
transition: 0.5s;
padding-top: 50px;
}
/* menu links*/
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 15px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover {
color: #F8EDF1 ;
}
.sidenav .closebtn {
position: absolute;
top: 10px;
right: 5px;
font-size: 30px;
margin-left: 50px;
}
}
#media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>
<div id="mySidenav" class="sidenav" style="font:5px/15px New Century Schoolbook, TeX Gyre Schola, serif;color:#340D0D">
×
<ul><li>Lab 1: Hello World</li><li>
Lab 2: Basic PHP Script</li><li>
Lab 3: Working with Data Types and Operators</li><li>
Lab 4</li><li>
Lab 6</li><li>
Lab 7</li><li>
Lab 8</li><li>
Lab 9</li><li>
Lab 10</li><li>
Lab 11</li><li>
Lab 12</li><li>
Lab 13</li><li>
Lab 14</li><li>
Lab 15</li><li>
Lab 16</li></ul>
</div>
<?php
define('LABTITLE', 'Laboratory Activity No. 3');
define('DESCRIPTION', 'Working with Data Types and Operators');
?>
<div style ='font:21px/31px New Century Schoolbook, TeX Gyre Schola, serif;color:#7B000B';cursor:pointer" onclick="openNav()">☰ THE LIST OF LABORATORIES </div>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
<?php
echo DESCRIPTION;
$myinteger = 10;
$myfloat = 10.57;
$mystring = "10 apples";
$myboolean = TRUE;
$mynull = NULL;
$myarray = array(1,2,3);
echo "<table border ='.5' width = '1000' cellspacing ='0'>";
// 1
echo '<tr bgcolor = "#E98195"><td><B>1. PHP Data Types </B><br></td></tr>';
echo '<tr><td>1a. $myinteger</td><td>', var_dump($myinteger), '</td></tr>';
echo '<tr><td>1b. $myfloat</td><td>', var_dump($myfloat), '</td></tr>';
echo '<tr><td>1c. $mystring</td><td>', var_dump($mystring), '</td></tr>';
echo '<tr><td>1d. $myboolean</td><td>', var_dump($myboolean), '</td></tr>';
echo '<tr><td>1e. $mynull</td><td>', var_dump($mynull), '</td></tr>';
echo '<tr><td>1f. $myarray</td><td>', var_dump($myarray), '</td></tr>';
//2
echo '<tr bgcolor = "#E98195"><td><B>2. PHP Arithmetic Operators</B><br></td></tr>';
echo '<br><tr><td>2a. $myinteger + 10</td><td>', var_dump($myinteger + 10), '</td></tr>';
echo '<br><tr><td>2b. $myinteger - 5</td><td>', var_dump($myinteger - 5), '</td></tr>';
echo '<br><tr><td>2c. $myinteger * 2</td><td>', var_dump($myinteger * 2), '</td></tr>';
echo '<br><tr><td>2d. $myinteger / 3</td><td>', var_dump($myinteger / 3), '</td></tr>';
echo '<tr><td>2e. $myboolean + 1</td><td>', var_dump($myboolean + 1), '</td></tr>';
echo '<tr><td>2f. $mystring * 2</td><td>', var_dump($mystring * 2), '</td></tr>';
//3
echo '<tr bgcolor = "#E98195"><td><B>3. PHP Bitwise Operators</B><br></td></tr>';
echo '<br><tr><td>2a. $myinteger + 10</td><td>', var_dump($myinteger + 10), '</td></tr>';
echo '<br><tr><td>2b. $myinteger - 5</td><td>', var_dump($myinteger - 5), '</td></tr>';
echo '<br><tr><td>2c. $myinteger * 2</td><td>', var_dump($myinteger * 2), '</td></tr>';
echo '<br><tr><td>2d. $myinteger / 3</td><td>', var_dump($myinteger / 3), '</td></tr>';
echo '<tr><td>2e. $myboolean + 1</td><td>', var_dump($myboolean + 1), '</td></tr>';
echo '<tr><td>2f. $mystring * 2</td><td>', var_dump($mystring * 2), '</td></tr>';
echo "</table>";
?>
<title><?php echo LABTITLE; ?></title>
</body>
</html>
Can anyone help me? : ( thanks.
You have too many br tags in your tables - between the table tags (tr / td / th / table) other tags are not allowed - removing them the problem is solved.

Save the generated HTML code to a file

I create an application that dynamically generates certain structures in Javascript and sends them to PHP in the resulting form. Generator is practically finished, although I have trouble writing the generated HTML code to a file. I have this PHP code and i want save generated HTML code to file. If i use this code:
$fp = fopen('plik.html', 'w');
fwrite($fp, file_get_contents('./generate.php'));
fclose($fp);
I get this file content:
error_reporting(E_ALL);
ini_set('display_errors',0);
#$tytul = $_POST['k-title'];
#$opis = $_POST['k-desc'];
$fp = fopen('plik.html', 'w');
fwrite($fp, file_get_contents('./generate.php'));
fclose($fp);
// albo dla PHP 5:
file_put_contents('plik.html', file_get_contents('./generate.php'));
/* echo "<pre>";
print_r($_POST);
echo "</pre>"; */
if ($tytul == '' || $opis == '') {
echo '<div><p>Błąd</p><p>Uzupełnij wszystkie pola generatora!</p>';
} else {
echo '<div style="max-width: 1050px; margin-left: auto; margin-right: auto;">';
echo '<div style="padding-top: 50px; padding-bottom: 50px;">';
echo '<p style="font-size: 30px; text-align: center;">'.$tytul.'</p>';
echo '<p style="font-size: 15px; text-align: justify;">'.$opis.'</p>';
echo '</div>';
echo '<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px;">Specyfikacja techniczna</div>';
echo '<table style="font-size: 14px; border: none; border-top: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; width: 100%;" border="0" cellspacing="0" cellpadding="5px"><tbody>';
$cechy = array_combine($_POST['cecha'], $_POST['cecha-opis']);
foreach($cechy as $klucz => $wartosc) {
echo '<tr><td style="padding: 3px 10px; text-align: right; border-right: 1px solid #dbdbdb;" width="50%">';
echo $klucz;
echo '</td>';
echo '<td style="padding: 3px 10px; text-align: left;" width="50%">';
echo $wartosc;
echo '</td>';
echo '</tr>';
}
echo '</tbody></table>';
$prezentacje = array();
for($i = 0; $i < count($_POST['pwidth']); $i++) {
$prezentacja = array();
$prezentacja['pwidth'] = $_POST['pwidth'][$i];
$prezentacja['pheight'] = $_POST['pheight'][$i];
$prezentacja['psource'] = $_POST['psource'][$i];
array_push($prezentacje, $prezentacja);
}
foreach($prezentacje as $p) {
echo '<img style="width: ' . $p['pwidth'] . 'px; height: ' . $p['pheight'] . 'px;" src="' . $p['psource'] . '" />';
}
echo '<div style="clear: both;"></div>';
$section = array();
for($a = 0; $a < count($_POST['sectionwidth']); $a++) {
$sesfull = array();
$sesfull['sectionwidth'] = $_POST['sectionwidth'][$a];
$sesfull['sectionheight'] = $_POST['sectionheight'][$a];
$sesfull['bg'] = $_POST['bg'][$a];
$sesfull['sectioncolor'] = $_POST['sectioncolor'][$a];
$sesfull['inputwidth'] = $_POST['inputwidth'][$a];
array_push($section, $sesfull);
}
foreach ($_POST['section'] as $sekcja) {
echo '<div style="margin: 0; float: left; width: '.$sekcja['sectionwidth'].'px; height: '.$sekcja['sectionheight'].'px; background: #'.$sekcja['bg'].'; color: #'.$sekcja['sectioncolor'].';">';
foreach ($sekcja['input'] as $input) {
echo '<p style="margin-left: auto; margin-right: auto; width: '.$input['inputwidth'].'px;">'.$input['inputtext'].'</p>';
}
echo '</div>';
}
echo '<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px; clear: both;">Galeria zdjęć</div>';
$gallery = array_combine($_POST['srcphoto'], $_POST['descphoto']);
foreach ($gallery as $source => $alt) {
echo '<img style="width: 100%; margin-bottom: 25px;" src="'.$source.'" alt="'.$alt.'" /></img>';
}
echo '</div>';
}
Is it possible to save only the generated HTML code by a PHP script while previewing the generated content?
Update #2:
<?php
error_reporting(E_ALL);
ini_set('display_errors',0);
$tytul = $_POST['k-title'];
$opis = $_POST['k-desc'];
ob_start(); ?>
<div style="max-width: 1050px; margin-left: auto; margin-right: auto;">
<div style="padding-top: 50px; padding-bottom: 50px;">
<p style="font-size: 30px; text-align: center;"><?php echo $tytul; ?></p>
<p style="font-size: 15px; text-align: justify;"><?php echo $opis; ?></p>
</div>
<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px;">Specyfikacja techniczna</div>
<table style="font-size: 14px; border: none; border-top: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; width: 100%;" border="0" cellspacing="0" cellpadding="5px"><tbody>
<?php
$cechy = array_combine($_POST['cecha'], $_POST['cecha-opis']);
foreach($cechy as $klucz => $wartosc) {
?>
<tr><td style="padding: 3px 10px; text-align: right; border-right: 1px solid #dbdbdb;" width="50%">
<?php echo $klucz ?>
</td>
<td style="padding: 3px 10px; text-align: left;" width="50%">
<?php echo $wartosc; ?>
</td>
</tr>
<?php
}
?>
</tbody></table>
<?php
$prezentacje = array();
for($i = 0; $i < count($_POST['pwidth']); $i++) {
$prezentacja = array();
$prezentacja['pwidth'] = $_POST['pwidth'][$i];
$prezentacja['pheight'] = $_POST['pheight'][$i];
$prezentacja['psource'] = $_POST['psource'][$i];
array_push($prezentacje, $prezentacja);
}
foreach($prezentacje as $p) {
?>
<img style="float: left; max-width: 100%; width:<?php echo $p['pwidth']; ?>px; height: <?php echo $p['pheight']; ?>px;" src="<?php echo $p['psource']; ?>" />
<?php
}
?>
<div style="clear: both;"></div>
<?php
$section = array();
for($a = 0; $a < count($_POST['sectionwidth']); $a++) {
$sesfull = array();
$sesfull['sectionwidth'] = $_POST['sectionwidth'][$a];
$sesfull['sectionheight'] = $_POST['sectionheight'][$a];
$sesfull['bg'] = $_POST['bg'][$a];
$sesfull['sectioncolor'] = $_POST['sectioncolor'][$a];
$sesfull['inputwidth'] = $_POST['inputwidth'][$a];
array_push($section, $sesfull);
}
foreach ($_POST['section'] as $sekcja) {
?>
<div style="margin: 0; float: left; width: <?php echo $sekcja['sectionwidth']; ?>px; height: <?php echo $sekcja['sectionheight']; ?>px; background: #<?php echo $sekcja['bg']; ?>; color: #<?php echo $sekcja['sectioncolor']; ?>;">
<?php
foreach ($sekcja['input'] as $input) {
?>
<p style="margin-left: auto; margin-right: auto; width: <?php echo $input['inputwidth']; ?>px"> <?php echo $input['inputtext']; ?> </p>
<?php } ?>
</div>
<?php
}
?>
<div style="width: 100%; text-align: center; background-color: #eee; font-weight: 200; line-height: 0.92em; padding: 23px 0; font-size: 30px; clear: both;">Galeria zdjęć</div>
<?php
$gallery = array_combine($_POST['srcphoto'], $_POST['descphoto']);
foreach ($gallery as $source => $alt) {
?>
<img style="width: 100%; margin-bottom: 25px;" src="<?php echo $source; ?>" alt="<?php echo $alt; ?>" /></img>
<?php } ?>
</div>
<?php
$szablon = ob_end_flush();
echo $szablon;
$fp = fopen('plik.html', 'w');
fwrite($fp, $szablon);
fclose($fp);
file_put_contents('plik.html', $szablon);
?>
You can use output buffering in your script (http://php.net/manual/en/book.outcontrol.php)
Something like...
ob_start();
echo 'Some html';
$text = ob_get_flush();
echo "Content is:".$text;
will output
Content is:Some html
Update:
If you wanted to capture all of the output which your generating, the ob_start(); starts the buffering (where you have it in your example is fine), then when you've generated what your after (so for example )...
</tbody></table>
<?php
$content = ob_get_flush();
fwrite($fp, $content);
You will have to get the generated HTML by accessing your generate.php script through a web server (e.g. http://localhost/generate.php, depending on where your code is located).
file_get_contents('http://localhost/generate.php');

prev/next links to show whats on different page in php

Okay so I have found after some long research a code that I will include here that adds prev/next url at bottom of page. What I am doing is making a portfolio that in the future I will add pages and remove, so I needed a php code that would run pages using the footer.php and go to next in line. Example it would show page1.php, page2.php, page3.php, page4.php and so on. That all works great in the code I have. What I would like now is to put a variable name on each page of what that portfolio piece will be then have it echo next to the previous and next button. I can get it to work, but it shows the existing name on each prev/next button.
If I am not making sense just tell me and I will explain it differently. I hope someone can help, been trying to get my portfolio done for some time now! :)
Here is my header.php
<html>
<head>
<title>PAGINATION TEST</title>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<nav>
<div id="nav_menu">
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</div>
</nav>
<body>
Here is my page1.php
<?php //THIS IS THE PREVIOUS/NEXT LINK TITLE FOR EACH PORTFOLIO PAGE
session_start();
$_SESSION['link-title'] = "wonder woman";
?>
<?php include('header.php') ?>
<div id="main_body">
PAGE 1
</div>
<?php include('footer.php') ?>
Here is my footer.php
<?php
session_start(); //this NEEDS to be at top of the page before any output etc
?>
<?php
$pinfo = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$reqpath = dirname($_SERVER["REQUEST_URI"]);
$linkname = ($_SESSION['link-title']);
if(preg_match("/(.*?)(\d+)\.php/", $pinfo["basename"], $matches)) {
$fnbase = $matches[1];
$fndir = $pinfo["dirname"];
$linkTitle = $linkname;
$current = intval($matches[2]);
$next = $current + 1;
$prior = $current - 1;
$next_file = $fndir . DIRECTORY_SEPARATOR . $fnbase . $next . ".php";
$prior_file = $fndir . DIRECTORY_SEPARATOR . $fnbase . $prior . ".php";
$next_link = $linkTitle . $next;
$prev_link = $linkTitle . $prior;
if(!file_exists($next_file)) $next_file = false;
if(!file_exists($prior_file)) $prior_file = false;
if($prior_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($prior_file);
// echo "Prior";
}
if($prior_file && $next_file) {
// echo " / ";
}
if($next_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($next_file);
// echo "Next";
}
if($prev_link) {
$prevTitle = $prev_link;
}
if($next_link) {
$Title = $next_link;
}
}
?>
<div id="pagination_container">
<div id="previous_link">
<!-- PREVIOUS -->
<?php if($prior_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($prior_file);
echo "PREVIOUS";
// echo $_SESSION['link-title'];
echo $prevTitle;
}
?>
</div>
<div id="next_link">
<!-- NEXT -->
<?php if($next_file) {
$link = $reqpath . DIRECTORY_SEPARATOR . basename($next_file);
echo $Title;
// echo $_SESSION['link-title'];
echo "NEXT";
}
?>
</div>
</div>
<div id="footer">
copyright blah blah
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</body>
</html>
here is my css
body,html {
padding: 0;
margin: 0;
overflow-x: hidden;
}
#nav_menu {
background-color: pink;
width: 100%;
height: 80px;
}
#nav_menu ul {
text-align: right;
}
#nav_menu li {
list-style-type: none;
display: inline-block;
padding-right: 20px;
padding-top: 30px;
}
#main_body {
width: 100%;
background-color: #dbdbdb;
height: 400px;
padding: 20px;
color: #333333;
}
#pagination_container {
width: 100%;
background-color: pink;
display: flex;
}
#previous_link {
width: 50%;
background-color: purple;
color: white;
display: flex;
float: left;
text-align: left;
padding-top: 50px;
padding-bottom: 50px;
padding-left: 20px;
}
#previous_link:hover {
color: white;
transition: 0.5s all;
}
#previous_link:link {
color: white;
text-decoration: none;
}
#next_link {
width: 50%;
background-color: purple;
color: white;
text-align: right;
padding-top: 50px;
padding-bottom: 50px;
padding-right: 20px;
border-left: 1px solid #dbdbdb;
}
#next_link a:visited {
color: white;
}
#next_link a:link {
color: white;
text-decoration: none;
}
#next_link a:hover {
color: blue;
transition: 0.5s all;
}
#next_link:hover {
background-color: pink;
transition: 0.5s all;
}
#footer {
text-align: center;
padding-top: 20px;
}
Here is page2.php for example of how it works now
<?php //THIS IS THE PREVIOUS/NEXT LINK TITLE FOR EACH PORTFOLIO PAGE
session_start();
$_SESSION['link-title'] = "superman";
?>
<?php include('header.php') ?>
<div id="main_body">
PAGE 2
</div>
<?php include('footer.php') ?>

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