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');
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'm developing a webpage that has many forms with some text close to form. This form and text are generated by a function, but I get this
As you can see the forms and the text are not aligned with forms and text below. I would like to have this:
(this work because I put spaces manually). This is how I create forms.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo $name;
echo '<input type="text" name="'. $product. '" id="'. $product. '" style="font-size:12pt;height:30px"/> x'.$productp. '€
price:'.$productpt.'€<br>';
}
echo '<form method="post" name="form1" id="form1" autocomplete="off">'; //start form
echo '<div class="leftpane">'; //start leftpane
echo '<h1>';
echo '<font size="6" color="red"> ALIMENTS </font><br>';
//ADD ELEMENTS IN MY MENU
//The first argument is the form name and id, the second is the name that will be printed(to the left of the form), the third argument is the price.
$menu[] = new Menu("pasta", "Pasta", 2);
$menu[] = new Menu("spaghetti", "Spaghetti", 1.50);
$menu[] = new Menu("pizza", "Pizza", 5);
$menu[] = new Menu("chicken_wings_x4", "Chicken Wings X4", 4.50);
$menu[] = new Menu("cheeseburger", "Cheeseburger", 6);
$menu[] = new Menu("Sandwich", "Sandwich", 2);
$menu[] = new Menu("hamburger", "Hamburger", 4.50);
$menu[] = new Menu("stuff", "stuff", 15.50);
//FOR EACH ELEMENT CREATE A FORM
for($i=0; $i<count($menu); $i++){
add_form($menu[$i]->form_name, $menu[$i]->name, $menu[$i]->price);
}
echo '</h1>';
echo '</div>'; //Close leftpane
...Do Others stuff in middlepane and in rightpane
To be clearer in html, for example the first form will be:
<input type="text" name="pasta" id="pasta" style="font-size:12pt;height:30px"/> x2€ price:X€<br>
I thought to divide in 3 parts my leftpane and to place $name to the left, the form to the middle and the price to the right. But the problem is that i create form in function, so I do not know how to do it.
This is my css:
<style>
input[type=text] {
width: 10%;
margin: 7.5px 0;
box-sizing: border-box;
}
input[type=submit].class1 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit].class2 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
margin: 0;
}
.container {
width: 100%;
height: 100%;
}
.leftpane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.middlepane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.rightpane {
width: 33%;
height: 100%;
position: relative;
float: right;
border-collapse: collapse;
}
form {
display: inline-block;
}
h1 {
font-size: 19.5px;
}
</style>
I would suggest you to use a table. https://www.w3schools.com/html/html_tables.asp
Or you could wrap every section into a div-container and define its width.
I think your output code would really benefit from some additional HTML structure with classes that allow you to control their layout in a consistent way with CSS. I would update the add_form() function:
function add_form($product,$name,$productp) {
$productpt = "X";
echo '<div class="form-wrap">';
echo '<span class="form-name">' . $name . '</span>';
echo '<input type="text" name="'. $product. '" id="'. $product. '"/> <span class="form-label">x'.$productp. '€</span> <span class="form-price">price:'.$productpt.'€</span>';
echo '</div>';
}
Then with the output having more targetable HTML structure you can do this with CSS:
.form-wrap input {
font-size: 12pt;
height: 30px
}
.form-name {
display: inline-block;
width: 100px;
margin-right: 20px;
}
.form-label {
display: inline-block;
margin-left: 5px;
margin-right: 20px;
}
<div class="form-wrap">
<span class="form-name">Something</span>
<input type="text" name="something" id="somethingId" />
<span class="form-label">x1€</span>
<span class="form-price">price:1€</span>
</div>
<div class="form-wrap">
<span class="form-name">Another one</span>
<input type="text" name="anotherone" id="somethingId2" />
<span class="form-label">x2€</span>
<span class="form-price">price:2€</span>
</div>
<div class="form-wrap">
<span class="form-name">Number Three</span>
<input type="text" name="thirdone" id="somethingId3" />
<span class="form-label">x3€</span>
<span class="form-price">price:3€</span>
</div>
Try this.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo "<table><tr>";
echo "<td width='20%'>" . $name . "</td>";
echo "<td width='20%'><input type='text' name='". $product . "' id='" . $product . "' style='font-size:12pt;height:30px;' /></td>";
echo "<td width='20%'>x" . $productp . "€</td>";
echo "<td width='20%'>price:" . $productpt . "€</td>";
echo "</tr></table>";
}
This is the php code I am modifying to have a header and a description text box appear above the slider. It works great if there is a header and description set within the slider, but on other pages I just want the image - instead an empty "text box" is displayed as it reads the <h2> and <br> tags.
Is there anyway I can make an if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image, if not empty show the boxes too?
css
.nivo-caption h2 {
font-size: xx-large;
color: #fff;
}
.theme-default .nivo-caption {
font-family: inherit;
font-size: 16px;
font-weight: bold;
/* z-index: 20; */
-moz-text-shadow: 1px 1px 0 #000;
-webkit-text-shadow: 1px 1px 0 #000;
text-shadow: 1px 1px 0 #000;
position: absolute;
left: 23px;
bottom: 20px;
background: rgba(58, 88, 129, 0.5);
color: #fff;
width: 95%;
z-index: 8;
padding: 5px 10px;
opacity: 1;
overflow: hidden;
display: none;
-moz-opacity: 1;
filter: alpha(opacity=1);
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
php
<div class="slider-wrapper <?php echo "theme-".$theme_title;?>" id="<?php echo "slider-wrapper-".$bID; ?>">
<div id="<?php echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
<?php
foreach($items as $item) {
echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';
echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'" data-thumb="'.$item['itemImageSrc'].'" >';
echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
}
?>
</div>
</div>
As you said if .$item['itemImageTitle'] & .$item['itemTitle'] empty show just the image. You can try this
<div class="slider-wrapper <?php echo "theme-".$theme_title;?>" id="<?php echo "slider-wrapper-".$bID; ?>">
<div id="<?php echo "nivo-slider-".$bID; ?>" class="nivoSlider" style="width: 100% !important;">
<?php
foreach($items as $item) {
echo (strlen($item['itemUrl'])>1) ? '<a href="'.$item['itemUrl'].'">' : '';
$my_title = "";
if(!empty($item['itemImageTitle']) && !empty($item['itemTitle'])){
$my_title = '<h2>'.$item['itemTitle'].'</h2><br>'.$item['itemImageTitle'].'</h2>';
}
echo '<img src="'.$item['itemImageSrc'].'" alt="'.$item['itemImageAlt'].'" title="'.$my_title.'" data-thumb="'.$item['itemImageSrc'].'" >';
echo (strlen($item['itemUrl'])>1) ? '</a>' : '';
}
?>
</div>
</div>
i have php program that contain div main_wrapper that div have two sub div resultwrapper and adv_right. I want adv_right div exactly right side of the resultwrapper div.When i'm use float mean that div present outside of the main_wrapper div.
<style>
.resultwrapper{width:990px; margin: 10px auto 10px auto; clear:both; }
.resultitem{ float: left;
height: 170px;
margin-bottom: 0px;
margin-left: 10px;
min-height: 130px;
width:218px;}
.resultleftitem{padding-left:0;margin-left:0px;}
.resultitem img{border:dotted 1px #666; padding:6px;}
.resultitem img:hover{border:solid 1px #F60;}
.resultitem h4{font-size:12px; font-weight:bold; color:#249ce9; margin-top:5px; }
.resultitem a{color:#249ce9;}
.resultitem .caption{color:#9c9c9c; font-size:12px; display:block; margin-top:6px; text-align:justify;}
</style>
<div class="main_warpper">
<div class="resultwrapper">
<?php
while($row = mysql_fetch_array($rs)) {
$id=$row['id'];
$type=$row['type'];
$location=$row['location'];
if(file_exists("properties//". $imageloc ."//thumb.jpg") )
{
$thumb_img="properties/". $imageloc ."/thumb.jpg";
} else {
$thumb_img="images/default.jpg";
}
if($cnt==0 || $cnt ==4 ) $newResult=true; else $newResult=false;
?>
<div id="parent" >
<div class="resultitem <?php if($newResult) echo ' resultleftitem'; ?>" id="resultitem"> <a href="viewpropdetails.php?id=<?php echo $id;?>" target="_blank">
<img id="parent" src="<?php echo $thumb_img; ?>" alt="<?php $new=strtolower($heading); echo ucwords($new); ?>" title="<?php $new=strtolower($heading); echo ucwords($new); ?>" width="100" height="100" /></a>
<div class="itemdetails">
<h4 id="linkheading"><?php echo $type ." # ".$location; ?></h4>
<span class="box"><?php echo cropStr($desc,$MAX_DESC); ?></span>
</div>
</div>
</div>
<?php
$cnt++; } ?>
</div>
<div class="adv_right" style=" clear:both; width:15%; float:right;height:300px; background-color:#999999;">
</div>
</div>
Please try it,
Remove clear:both; from both div and set width what u want ,,
Please try this code you want like this ??
<style>
.resultwrapper {
margin: 10px auto 10px auto;
}
.resultitem {
float: left;
height: 170px;
margin-bottom: 0px;
margin-left: 10px;
min-height: 130px;
width:218px;
}
.resultleftitem {
padding-left:0;
margin-left:0px;
}
.resultitem img {
border:dotted 1px #666;
padding:6px;
}
.resultitem img:hover {
border:solid 1px #F60;
}
.resultitem h4 {
font-size:12px;
font-weight:bold;
color:#249ce9;
margin-top:5px;
}
.resultitem a {
color:#249ce9;
}
.resultitem .caption {
color:#9c9c9c;
font-size:12px;
display:block;
margin-top:6px;
text-align:justify;
}
</style>
<div class="main_warpper">
<div class="resultwrapper">
<?php
while($row = mysql_fetch_array($rs)) {
$id=$row['id'];
$type=$row['type'];
$location=$row['location'];
if(file_exists("properties//". $imageloc ."//thumb.jpg") )
{
$thumb_img="properties/". $imageloc ."/thumb.jpg";
} else {
$thumb_img="images/default.jpg";
}
if($cnt==0 || $cnt ==4 ) $newResult=true; else $newResult=false;
?>
<div id="parent" >
<div class="resultitem <?php if($newResult) echo ' resultleftitem'; ?>" id="resultitem"> <img id="parent" src="<?php echo $thumb_img; ?>" alt="<?php $new=strtolower($heading); echo ucwords($new); ?>" title="<?php $new=strtolower($heading); echo ucwords($new); ?>" width="100" height="100" />
<div class="itemdetails">
<h4 id="linkheading"><?php echo $type ." # ".$location; ?></h4>
<span class="box"><?php echo cropStr($desc,$MAX_DESC); ?></span> </div>
</div>
</div>
<?php
$cnt++; } ?>
</div>
<div class="adv_right" style="width:15%; float:right;height:300px; background-color:#999999;">23123 </div>
</div>
add float:left here
<div class="resultwrapper" style="float:left;">
and rempove clear:both and add float:left
<div class="adv_right" style=" clear:both; width:15%; float:left;height:300px;
background-color:#999999;">
see demo here ....http://jsfiddle.net/6e4xN/1/
when you going to use this code it will not work with more than 7-8 elements, to work when you have more elements then use below stylesheet.
<style>
.resultwrapper {
margin: 10px auto 10px auto;
width:80%;
float:left;
}
.resultitem {
float: left;
height: 170px;
margin-bottom: 0px;
margin-left: 10px;
min-height: 130px;
width:150px;
}
.resultleftitem {
padding-left:0;
margin-left:0px;
}
.resultitem img {
border:dotted 1px #666;
padding:6px;
}
.resultitem img:hover {
border:solid 1px #F60;
}
.resultitem h4 {
font-size:12px;
font-weight:bold;
color:#249ce9;
margin-top:5px;
}
.resultitem a {
color:#249ce9;
}
.resultitem .caption {
color:#9c9c9c;
font-size:12px;
display:block;
margin-top:6px;
text-align:justify;
}
</style>
Let me know if it works for you or not.
I guess there is some problem in the code. You CANNOT use the same ID for multiple elements in a page. Secondly when you are using percent width for the adv_right div, why don't you use the same for resultwrapper div with both the resultwrapper & adv_right divs floated left and no clear:both in the css. I feel this should solve your problem.
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I am currently encountering a problem that keeps giving me the error on the question title. here is my code, can anyone help me check what is wrong and how to fix it? Thank you so much.
The following part is the bottom part of a php file including "Header":
echo'<table>';
while ($result = mysql_fetch_array($sql, MYSQL_ASSOC)){
echo '<tr>';
echo '<td style="width:142px">';
echo $result['instrument_id'];
echo '</td>';
echo '<td style="width:142px">';
echo $result['instrument'];
echo '</td>';
echo '<td style="width:142px">';
echo $result['type'];
echo '<br>';
echo $result['amount'].' shares';
echo '</td>';
echo '<td style="width:142px">';
echo $result['opening_rate'];
echo '<br>';
$fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s='".$result['instrument']."'&f=nsb2b3p2ophg.csv","r");
//this uses the fgetcsv function to store the quote info in the array $data
$data = fgetcsv ($fp, 1000, ",");
echo ($data[3]);//current rate
echo '</td>';
echo '<td style="width:142px">';
echo $result['opening_value'];
echo '<br>';
$value = $data[3] * $result['amount'];
$currentvalue = number_format($value, 2, '.', '');
echo $currentvalue;//current value
echo '</td>';
echo '<td style="width:142px">';
echo $result['open_time'];
echo '</td>';
echo '<td style="width:142px">';
if($data[3] == 0){
echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close" disabled="disabled"/>';}
else{
echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close"/>';}
echo '</td>';
echo '</tr>';
fclose ($fp);
$name = 'close'.$result['instrument_id'];
$close = isset($_POST[$name]);
if($close){
$instrumentid = $result['instrument_id'];
$_SESSION['instrumentid'] = $instrumentid;
$instrument = $result['instrument'];
$_SESSION['instrument'] = $instrument;
$amount = $result['amount'];
$_SESSION['amount'] = $amount;
header("Location:order_sell.php");
}
}
echo'</table>';
When I include a file on the top, which is the background file, only including html elements, it will give me the error message like Warning: Cannot modify header information ...
here is the code for the included file:
<?php
session_start();
// checks if $_SESSION['userid'] exists
$areYouLoggedIn = isset($_SESSION['username']);
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
/* background*/
body { background: url(images/background2.png) center center fixed no-repeat;
webkit-background-size:cover;
moz-bacground-size:cover;
-o-background-size:cover;
background-size:cover;}
/* top menu layout*/
.Topmenu{
width:1000px;
background: #00AEEF;
border-radius: 3px 3px 3px 3px;
}
/* top menu cell layout*/
.Tabcells{ width:200px;
text-align:center;
}
/* top menu cell text layout*/
/* top menu cell text layout*/
.Tabtexteffect
{ text-decoration: none;
color:white;
font-family:Arial;
font-size:15px;
}
.Tabtexteffect:hover
{
text-decoration: none;
color:white;
font-family:Arial;
font-size:20px;
}
.Paragraph {text-align:justify;
text-justify:distributed-all-lines;
text-align-last:justify;
font-family:arial;
font-size:12pt;
width:1000px;
}
.Box {
width:950px;
text-align:left;
background: -webkit-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent;
background: -moz-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent;
border: 1px solid #AAAAAA;
border-radius: 10px 10px 10px 10px;
box-shadow: 0 0 15px #AAAAAA;
}
.Box2 {
width: 200px;
text-align: left;
background: -webkit-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent;
background: -moz-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent;
border: 1px solid #AAAAAA;
border-radius: 10px 10px 10px 10px;
box-shadow: 0 0 15px #AAAAAA;
}
.Button {
background: -moz-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent;
background: -webkit-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent;
border: 1px solid #093C75;
border-radius: 3px 3px 3px 3px;
box-shadow: 0 1px 0 #FFFFFF;
color: #FFFFFF;
cursor: pointer;
font-family: Arial,sans-serif;
font-size: 12px;
font-weight: bold;
margin-right: -16px;
margin-top: 16px;
padding: 5px 10px;
text-decoration: none;
text-shadow: 0 1px 1px #333333;
text-transform: uppercase;
}
</style>
</head>
<body>
<form action="HomePage.php" method="POST">
<div style="width:1000px; margin:0 auto; min-height:100%;">
<div>
<img style="width:25%;" src="images/Mock Apprentice.png" alt="Mock Apprentice"></img>
<?php
if($areYouLoggedIn==false){
echo'<table cellpadding="0" align="right" style="position: absolute; left: 940px; top: 15px;">';
echo'<tr>';
echo'<td width="130" align="center"><font face="Arial" size="3"><input type="button" class="Button" value="Sign In""/></font></td>';
echo'<td width="1" bgcolor=black><BR></td>';
echo'<td width="100" align="center"><font face="Arial" size="3"><input type="button" class="Button" value="Sign Up""/></font></td>';
echo'</tr>';
echo'</table>';
}
if($areYouLoggedIn == true){
echo'<table cellpadding="0" align="right" style="position: absolute; left: 950px; top: 40px;">';
echo'<tr>';
echo'<td width="130" align="center"><font face="Arial" size="4" color="#00AEFF">Welcome';
echo' ';
echo'<font color="#FFD700">';
echo($_SESSION['username']);
echo'</font>';
echo'</font></td>';
echo'<td width="1" bgcolor=black><BR></td>';
echo'<td width="100" align="center"><font face="Arial" size="4"><a style="text-decoration: none; color:#00AEFF;" href="Logout.php">Logout</a></font></td>';
echo'</tr>';
echo'<table>';
}
?>
<HR color="#00AEEF">
</div>
<div>
<table width="1020" height="30" class="Topmenu">
<tr>
<td width="200" height="30" class="Tabcells">Intro</td>
<td width="200" class="Tabcells">How to use</td>
<td width="200" class="Tabcells">Education Center</td>
<td width="200" class="Tabcells">Trading Platform</td>
<td width="196" class="Tabcells">Contact Us</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
Thank you so so so much!
Try replacing header("Location:order_sell.php"); with
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=order_sell.php">';
exit;
Whatever you output - being HTML only or output from PHP: Unless you do some tricking with the ob_*() functions you lose the ability to send headers the moment you output anything.
This is why they are called headers: In the HTTP protocol they preceed every single piece of payload body - including whitespace such as empty lines before a <?php tag.
The typical way to tackle this would be to regroup your logic as to first calculate what headers you need, then create your output, via echo(), printf(), include() or whatever.
In PHP header functions must be called before any output is sent from the server. This includes echo calls as well as HTML info before the <?php ?> block.
You can't send a header after any text has been sent to the browser:
header("Location:order_sell.php");
Needs to be before ANY text/output/whitespace is sent/echo'ed to the browser.
When using header("Location:someLocation") be sure that you don't have any character outputted to the browser, otherwise you'll get the error Cannot modify header information. More on this at: http://php.net/manual/en/function.header.php