PHP Searchbar only showing 1 result - php

I am trying to create a search bar in php.
I want to retrieve data from my database.
The problem is only that if I search I get only 1 result.
How do I solve this?
Or is there another way in which I get this working?
My code:
<?php
include("config.php");
session_start();
$zoekopdracht = $_GET['search'];
$categorie = $_GET['categorie'];
$zoekopdracht = mysqli_real_escape_string($db,$zoekopdracht);
$sql = ("SELECT * FROM activiteiten WHERE `inhoud` LIKE '%$zoekopdracht%'");
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$activiteit_id = $row['activiteit_id'];
$naamsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'naam'");
$naamresult = mysqli_query($db,$naamsql);
$naamrow = mysqli_fetch_array($naamresult,MYSQLI_ASSOC);
$beschrijvingsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'beschrijving'");
$beschrijvingresult = mysqli_query($db,$beschrijvingsql);
$beschrijvingrow = mysqli_fetch_array($beschrijvingresult,MYSQLI_ASSOC);
result bar:
<?php
if(mysqli_num_rows($result) > 0){
?>
<div class="Row" id="main" style="border: 2px solid #51BAA4;border-radius: 4px; height: 0px; width: 100%;padding: 0em 0 0em 0; margin: 0 auto; display: table;">
<div class="Column" id="plaatje" style="padding: 0em 0 0em 0;">
<left><img src="images/noimage.png" height="100px" width="100px" alt=""></left>
</div>
<div class="Column" id="titel">
<div style="text-align: left;position:relative;margin:0px;width:10%;height:40px;padding-top: 3px; font-size:125%; display: -webkit-box;-webkit-line-clamp: 1;">
<left><h3><?php echo $naamrow['inhoud'];?></h3>
</div>
<div style="text-align: left; height: 0px;width: 450px; word-wrap: break-word;white-space: initial;position:absolute;">
<p style=" overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical"><?php echo "<b>"; echo $naamrow['inhoud']; echo "</b>, "; echo $beschrijvingrow['inhoud']; ?></p>
</div>
</div>
</div>
<?php
}
?>

You are process only first record there. You need to repeat for all the return value.
//$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$naamrows = [];
$beschrijvingrow = [];
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$activiteit_id = $row['activiteit_id'];
$naamsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'naam'");
$naamresult = mysqli_query($db,$naamsql);
$naamrow = mysqli_fetch_array($naamresult,MYSQLI_ASSOC);
$beschrijvingsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'beschrijving'");
$beschrijvingresult = mysqli_query($db,$beschrijvingsql);
$beschrijvingrow = mysqli_fetch_array($beschrijvingresult,MYSQLI_ASSOC);
// Store you data in array to be use later
array_push($naamrows,$naamrow);
array_push($beschrijvingrows,$beschrijvingrow);
}
Now change you template to iterate the array to render all.
<?php foreach ($naamrows as $key => $naamrow) { ?>
<div class="Row" id="main"
style="border: 2px solid #51BAA4;border-radius: 4px; height: 0px; width: 100%;padding: 0em 0 0em 0; margin: 0 auto; display: table;">
<div class="Column" id="plaatje" style="padding: 0em 0 0em 0;">
<left><img src="images/noimage.png" height="100px" width="100px" alt=""></left>
</div>
<div class="Column" id="titel">
<div
style="text-align: left;position:relative;margin:0px;width:10%;height:40px;padding-top: 3px; font-size:125%; display: -webkit-box;-webkit-line-clamp: 1;">
<left>
<h3><?php echo $naamrow['inhoud'];?></h3>
</div>
<div
style="text-align: left; height: 0px;width: 450px; word-wrap: break-word;white-space: initial;position:absolute;">
<p style=" overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical">
<?php echo "<b>"; echo $naamrow['inhoud']; echo "</b>, "; echo $beschrijvingrows[$key]['inhoud']; ?></p>
</div>
</div>
</div>
<?php } ?>

Related

problem showing repeated whole page when trying to display data from database

I'm trying to display the data from the database, but whenever I connect it the whole page gets repeated - from the head title to a row and then it shows the head title again as if I had split the page, and another row from the database.
I want to show the data like the products page next to each other but it only shows one and then repeats the whole page.
This is my code that I tried - the page gets repeated from the main-container and shows one row, then repeats the main container again.
<?php
require_once 'opp_data.php';
$sql ="SELECT * FROM college_opp";
$allopp =$conn->query($sql);
?>
//i dont know if i have to show the whole code but this is only the code part where everything gets repeated
<?php
while ($row = mysqli_fetch_assoc($allopp)) {
?>
<div class="main-container">
<h2>تصفح الفرص التطوعية </h2>
<div class="post-collect">
<div class="post-main-container">
<div class="all sports">
<div class="post-img">
<img src="imgs/<?php echo $row["images"]; ?>">
<span class="category-name" data-name="sporty">كلية علوم الرياضة </span>
</div>
<div class="post-content">
<div class="post-content-top">
<span>
<i class="fa-solid fa-users-line"></i><?php echo $row["volunteer_num"]; ?>
</span>
<span><i class="fa-regular fa-calendar-days"></i><?php echo $row["Date"]; ?></span>
</div>
<h2>"<?php echo $row["Title"]; ?>"</h2>
<p>"<?php echo $row["Description"]; ?>"</p>
</div>
<div class="button-btn">
التفاصيل والتسجيل
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
</body>
for the style.css\\
.main-container{
width: 90vw;
margin: 0 auto;
padding: 40px 0;
}
.main-container h2{
text-align: center;
padding: 90px 0;
font-size: 32px;
color: #fff;
}
.main-container p{
font-weight: 300;
padding: 10px 0;
opacity: 0.7;
text-align: center;
}
.post-main-container{
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 60px;
}
.post-main-container div{
box-shadow: 0px 8px 27px -12px rgba(0, 0, 0, 0.64);
}
.post-img{
position: relative;
width: 2vw;
height: 19vw;
}
.post-img img{
position: absolute;
left: 20px;
width: 17vw;
height: 19vw;
}
.post-content{
padding: 25px;
}
.post-content-top{
background: #2b1055;
color: #fff;
opacity: 0,9;
padding: 5px 0 5px 15px;
}
.post-content-top span{
padding-right: 20px;
}
.post-content h2{
font-size: 22px;
padding: 12px 0;
font-weight: 400;
}
.post-content p{
opacity: 0.7;
font-size: 15px;
line-height: 1.8;
color: ghostwhite;
}
.button-btn a {
padding: 8px 15px;
display: block;
font-family:'Almarai', sans-serif ;
font-size: 15px;
cursor: pointer;
background: transparent;
border-radius: 20px;
width: 50%;
border: 2px solid #fff;
color: #fff;
margin: 5px auto;
padding: 0.4rem;
text-decoration: none;
font-weight: 600;
transition: all 0.2s ease-in-out;
}
.button-btn a:hover{
background:#2b1055;
}
Because your entire page is in the while loop it will duplicate the whole page multiple times. I don't know if this is exactly what you want but I suggest you doing it something like this:
<?php
require_once 'opp_data.php';
$sql ="SELECT * FROM college_opp";
$allopp =$conn->query($sql);
?>
<div class="main-container">
<h2>تصفح الفرص التطوعية </h2>
<div class="post-collect">
<?php while ($row = mysqli_fetch_assoc($allopp)) { ?>
<div class="post-main-container">
<div class="all sports">
<div class="post-img">
<img src="imgs/<?php echo $row[" images "]; ?>">
<span class="category-name" data-name="sporty">كلية علوم الرياضة </span>
</div>
<div class="post-content">
<div class="post-content-top">
<span>
<i class="fa-solid fa-users-line"></i><?php echo $row["volunteer_num"]; ?>
</span>
<span><i class="fa-regular fa-calendar-days"></i><?php echo $row["Date"]; ?></span>
</div>
<h2>"
<?php echo $row["Title"]; ?>"</h2>
<p>"
<?php echo $row["Description"]; ?>"</p>
</div>
<div class="button-btn">
التفاصيل والتسجيل
</div>
</div>
</div>
<?php } ?>
</div>
</div>
This will only loop the post-main-container.
This is the code you are looking for
<div class="main-container">
<h2>تصفح الفرص التطوعية </h2>
<div class="post-collect">
<div class="post-main-container">
<?php
while ($row = mysqli_fetch_assoc($allopp)) {
?>
<div class="all sports">
<div class="post-img">
<img src="imgs/<?php echo $row["images"]; ?>">
<span class="category-name" data-name="sporty">كلية علوم الرياضة </span>
</div>
<div class="post-content">
<div class="post-content-top">
<span>
<i class="fa-solid fa-users-line"></i><?php echo $row["volunteer_num"]; ?>
</span>
<span>
<i class="fa-regular fa-calendar-days"></i><?php echo $row["Date"]; ?>
</span>
</div>
<h2>"<?php echo $row["Title"]; ?>"</h2>
<p>"<?php echo $row["Description"]; ?>"</p>
</div>
<div class="button-btn">
التفاصيل والتسجيل
</div>
</div>
<?php
}
?>
</div>
</div>
</div>

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

I'm currently trying to make a blog. When I try to make a "preview" of the body of the post. The first post seems to be fine, but the second post goes over its div. I tried changing what tags to use and css formatting but it stays like that.
My code:
HTML
<div class="module">
<div class="blog">
<div class="recents">
<h2>Recent Posts</h2>
<br><br>
<?php
$sql = "select title, body, created_at FROM posts";
$result = mysqli_query($link, $sql);
$query = mysqli_query($link, $sql) or die(mysqli_error($link));
while ($row = mysqli_fetch_assoc($query)) {
$title = $row['title'];
$body = $row['body'];
$created_at = $row['created_at'];
if (strlen($body) > 500) {
$body = substr($body, 0, 500);
}
echo "<h3>" . $title . "</h3><br>";
echo "<p>" . $body . "</p>";
echo "<small>" . $created_at . "</small>";
echo "<br><br>";
}
?>
</div>
<div class="categories">
<h3>Categories</h3>
</div>
</div>
CSS
html {
font-family: 'IBM Plex Serif', serif;
}
.module {
background-color: #fffff7;
box-shadow: 3px 10px 18px #888888;
padding-top: 70px;
padding-left: 130px;
border: 1px solid;
width: 1080px;
margin-left: 380px;
height: 821px;
}
.blog {
display: flex;
flex-direction: row;
text-align: left;
}
.recents {
flex-grow: 2;
width: 570px;
}
.categories {
flex-grow: 1;
}
Any help would be appreciated.
It is because there are no spaces
to fix this try this:
word-wrap: break-word;

How to pass a php array as a post parameter in ajax call to a php file in the url

I want to pass a php array as a parameter to ajax call.I have done it with json_encode and JSON.parse . But I am ending up with a
Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse ()
This is for an php application developed with XAMPP Server.
**myfile.php**
This is the file where I have a view link.On clicking that link , I need to pass the array data to the post file in the ajax, where I will display the content inside the modal.
For that I have used the json_encode() and JSON.parse() , but I am ending up with this error.
<?php
$arrOne = array('test_arg_one' => 'Arg One','test_arg_two' => 'Arg Two','test_arg_three' => 'Arg Three');
$arrTwo = array('test_arg_one' => 'Arg One','test_arg_two' => 'Arg Two','test_arg_three' => 'Arg Three');
$arrThree = array('test_arg_one' => 'Arg One','test_arg_two' => 'Arg Two','test_arg_three' => 'Arg Three');
$json_one = json_encode($arrOne);
$json_two = json_encode($arrTwo);
$json_three = json_encode($arrThree);
?>
<html>
<form >
VIEW
</form>
<div id="MyModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog" style=" margin-top: -12%;">
<!-- Modal Content: begins -->
<div class="modal-content" style="width: 950px; margin-left: -190px;">
<div class="modal-header qutviewhead">
<h4 class="modal-title" style="text-align: center; margin-right: 305px;">Test</h4>
<!-- <button type="button" class="close qotviewclosebtn" data-dismiss="modal">×</button> -->
</div>
<!-- Modal Body -->
<div class="modal-body meadqrypopmdbody" style="height: 560px; overflow: scroll; overflow-x: hidden;">
<div class="header">
<img src="img1.jpg" style="width: 100%; height: 130px;">
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 15%;">
<img src="img2.jpg" style="padding-top: 15px; width: 105px; height: 100%" align="left">
</div>
<div style="width: 85%;background: url('img3.jpg'); background-repeat: no-repeat; background-position: center; margin-top: 15px;">
<div id="div_one">
<div class="test-one">
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; text-align: center;">
<p style="background: #2e3192; color: #fff; padding: 10px 10px;">Plot No.1148, West End Colony, Anna Nagar West Extension, Chennai-600 050. <br>
Ph : 044-26257357, 90421 33333. Email : abishek#senthilsafety.com, Web : www.ssspl.in
</p>
</div>
<div class="header">
<img src="img1.jpg" style="width: 100%; height: 130px;">
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 15%;">
<img src="img2.jpg" style="padding-top: 15px; width: 105px; height: 100%" align="left">
</div>
<div style="width: 85%;background: url('img3.jpg'); background-repeat: no-repeat; background-position: center; margin-top: 15px;">
<div id="div_two">
<div class="test-two">
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; text-align: center;">
<p style="background: #2e3192; color: #fff; padding: 10px 10px;">Plot No.1148, West End Colony, Anna Nagar West Extension, Chennai-600 050. <br>
Ph : 044-26257357, 90421 33333. Email : abishek#senthilsafety.com, Web : www.ssspl.in
</p>
</div>
<div class="header">
<img src="img1.jpg" style="width: 100%; height: 130px;">
</div>
<div style="display: flex; flex-wrap: wrap;">
<div style="width: 15%;">
<img src="img2.jpg" style="padding-top: 15px; width: 105px; height: 100%" align="left">
</div>
<div style="width: 85%;background: url('img3.jpg'); background-repeat: no-repeat; background-position: center; margin-top: 15px;">
<div id="div_three">
<div class="test-three">
</div>
</div>
</div>
</div>
<div style="margin-top: 15px; text-align: center;">
</div>
</div>
<div class="cusfooter">
<button type="button" class="btn btn-default modcanbtn" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</html>
$('.view_data').click(function(){
var record = $(this).attr("id");
var obj = JSON.parse('<?= $json_one; ?>');
var facArg1 = obj.arg1;
var facArg2 = obj.arg2;
var facArg3 = obj.arg3;
var obj1 = JSON.parse('<?= $json_two; ?>');
var facArg11 = obj1.arg1;
var facArg21 = obj1.arg2;
var facArg31 = obj1.arg3;
var obj2 = JSON.parse('<?= $json_three; ?>');
var facArg12 = obj2.arg1;
var facArg22 = obj2.arg2;
var facArg32 = obj2.arg3;
$.ajax({
url:"testCat.php",
method:"post",
data:{'id':record,'facArg1':facArg1,'facArg2':facArg2,'facArg3':facArg3,'facArg11':facArg11,'facArg21':facArg21,'facArg31':facArg31,'facArg12':facArg12,'facArg22':facArg22,'facArg32':facArg32},
success:function(data){
var divs = data.split('------');
$(".test-one").html(divs[0]);
$(".test-two").html(divs[1]);
$(".test-three").html(divs[2]);
$("#MyModal").modal("show");
}
});
})
**testCat.php** [file in the ajax call]
This the content getting displayed inside the modal.
if(isset($_POST['cert_id']))
{
$output_one = '<style>
.borderNone table,td,th{
border:none!important;
text-align:left !important;
padding:0px !important;
}
</style>
<div style="text-align:center;">
<section>
<table align="right">
<tr>
<th style="text-align: right;">Date: 20/09/2019</th>
</tr>
</table>
</section>
<section>
<div style="padding-top:35px;"></div>
<p><b><u>TEST FORM</u></b></p>
<p><b>SEC</b></p>
</section>
<br>
<section>
<table style="border:none;">';
$arrValues = array();
if(isset($_POST['facArg1']) && ($_POST['facArg1'] != '')){
$arrValues['arg_one'] = $_POST['facArg1'];
}
if(isset($_POST['facArg2']) && ($_POST['facArg2'] != '')){
$arrValues['arg_two'] = $_POST['facArg2'];
}
if(isset($_POST['facArg3']) && ($_POST['facArg3'] != '')){
$arrValues['arg_three'] = $_POST['facArg3'];
}
$i = 1;
foreach($arrValues as $key => $val){
$output_one .='<tr>
<td>'.$i.'.'.$key.'</td>
<td>'.$val.'</td>
</tr>';
$i++;
}
$i = count($arrValues) + 1;
foreach($pdfOne as $key => $val){
$output_one .= '<tr>
<td>'.$i.'.'.$key.'</td>
<td style="padding: 0px 0px 0px 40px !important;">'.$val.'</td>
</tr>';
$i++;
}
$output_one .= '</table>
</section></div>
<br>';
$output_two = '
<div style="text-align:center;"><section>
<table align="right">
<tr>
<th style="text-align: right;">Date: 20/09/2019</th>
</tr>
</table>
</section>
<section>
<div style="padding-top:35px;"></div>
<p><b><u>TEST 2</u></b></p>
</section>
<br>
<section>
<table style="border:none;">';
$arrValuesOne = array();
if(isset($_POST['facArg11']) && ($_POST['facArg11'] != '')){
$arrValuesOne['arg_one'] = $_POST['facArg11'];
}
if(isset($_POST['facVillage21']) && ($_POST['facVillage21'] != '')){
$arrValuesOne['arg_two'] = $_POST['facArg21'];
}
if(isset($_POST['facAdd31']) && ($_POST['facAdd31'] != '')){
$arrValuesOne['arg_three'] = $_POST['facArg31'];
}
$i = 1;
foreach($arrValuesOne as $key => $val){
$output_two .='<tr>
<td>'.$i.'.'.$key.'</td>
<td>'.$val.'</td>
</tr>';
$i++;
}
$i = count($arrValuesOne) + 1;
foreach($pdfTwo as $key => $val){
$output_two .= '<tr>
<td>'.$i.'.'.$key.'</td>
<td style="padding: 0px 0px 0px 40px !important;">'.$val.'</td>
</tr>';
$i++;
}
$output_two .= '</table>
</section></div>
<br>';
$output_three = '<style>
.borderNone table,td,th{
border:none!important;
text-align:left !important;
padding:0px !important;
}
</style>
<div style="text-align:center;"><section>
<table align="right">
<tr>
<th style="text-align: right;">Date:20/09/2019</th>
</tr>
</table>
</section>
<section>
<div style="padding-top:35px;"></div>
<p><b><u>TET</u></b></p>
</section>
<br>
<section>
<table style="border:none;">';
$arrValuesTwo = array();
if(isset($_POST['facName12']) && ($_POST['facName12'] != '')){
$arrValuesTwo['arg_one'] = $_POST['facName12'];
}
if(isset($_POST['facVillage22']) && ($_POST['facVillage22'] != '')){
$arrValuesTwo['arg_two'] = $_POST['facVillage22'];
}
if(isset($_POST['facAdd32']) && ($_POST['facAdd32'] != '')){
$arrValuesTwo['arg_three'] = $_POST['facAdd32'];
}
$i = 1;
foreach($arrValuesTwo as $key => $val){
$output_three .='<tr>
<td>'.$i.'.'.$key.'</td>
<td>'.$val.'</td>
</tr>';
$i++;
}
$i = count($arrValuesTwo) + 1;
foreach($pdfThree as $key => $val){
$output_three .= '<tr>
<td>'.$i.'.'.$key.'</td>
<td style="padding: 0px 0px 0px 40px !important;">'.$val.'</td>
</tr>';
$i++;
}
$output_three .= '</table>
</section></div>
<br>';
$output_two = '<div class="break-before"></div>'.$output_two;
$output_three = '<div class="break-before"></div>'.$output_three;
echo $output_one.'------'.$output_two.'------'.$output_three;
}
Kindly help me to solve this error.
Uncaught SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at HTMLAnchorElement.<anonymous> (myfile.php:1093)
at HTMLAnchorElement.dispatch (jquery.3.2.1.min.js:3)
at HTMLAnchorElement.q.handle (jquery.3.2.1.min.js:3)
I want the array values to get displayed inside the modal.

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

why it float left is not working and these codes

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

Categories