Why I cant display the data I echo from the database in a PDF file ?
I used DOMPDF to convert my html. Anyone please help.
Here is the PDF result
PDF result image
Here is connection code
<?php
$id = $_GET['id'];
$conn = pg_connect("host=localhost dbname=mydatabase user=postgres password=admin");
if (!$conn) {
echo "An error occurred. cannot connectect to localhost.\n";
exit;
}
$sql = pg_query($conn, "SELECT * FROM mytable WHERE reference_no = $id ");
if (!$sql) {
echo "Error Ariel 7:50 !!!.\n";
}
while ($row = pg_fetch_assoc($sql)) {
$reference_no = $row['reference_no'];
$wo_name = $row['wo_name'];
}
Here is my convertion code:
error_reporting(0);
require_once ('xdompdf/dompdf_config.inc.php');
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno"><?php echo $reference_no;?></div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname"><?php echo $wo_name;?></div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>'
;
$name = date("Ymd").rand().'.pdf';
$reportPDF=createPDF(12, $pdf_content, 'activity_Report', $name );
function createPDF($pdf_userid, $pdf_content, $pdf_For, $filename){
$path='xdompdf/';
/*$rndNumber=rand();
$filename=$pdf_userid.date("Ymd").$rndNumber.'.pdf';*/
$dompdf=new DOMPDF();
$dompdf->load_html($pdf_content);
$dompdf->render();
$output = $dompdf->output();
file_put_contents($path.$filename, $output);
return $filename;
}
echo '<a href="xdompdf/'.$name.'" > Download </a>';
?>
Please Help me how to display the data.
Change $pdf_content to
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno">' . $reference_no . '</div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname">' . $wo_name . '</div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>';
I think you just need to concat your data in $pdf_content :
$pdf_content='
<style type="text/css">
div.refno{padding-left: 190px;}
.line{padding-left: 260px; padding-top: -37px;}
</style>
<body>
<div>
<h4> Work Order Form </h4>
<p> Reference No. <div class="refno">'.$reference_no.'</div> </p>
<p class="line">:_________________________________________________</p>
<p> Work Order Name <div class="woname">'.$wo_name.'</div> </p>
<p class="line">:_________________________________________________</p>
</div>
</body>';
Related
<?php
include ("db.php");
session_start();
$user = $_SESSION["user"];
if (isset($_POST["submit"])) {
$target_dir = "pics/";
$target_file = $target_dir . basename($_FILES["img"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
//check if there was an error
if ($uploadOk == 0) {
echo "The file couldnt be upload, please try again";
} else {
if (move_uploaded_file($_FILES["img"]["tmp_name"], $target_file)) {
echo "The file has been uploaded";
} else {
echo "Sorry there was a error";
}
}
$img = $_FILES['img']['name'];
$title = $_POST["cardname"];
$info = $_POST["description"];
$insta = $_POST["insta"];
$snap = $_POST["snap"];
$code = $_POST["code"];
$bg = $_POST["bg"];
$discord = $_POST["discord"];
$sql = "SELECT * FROM cards WHERE code = '".$code."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Please pick a new id, that one is already taken";
} else {
$sql = "INSERT INTO cards (title, user, link, code, image, description, likes, snap, insta, yt, bg, discord)
VALUES ('$title', '$user', '$link', '$code', '$img', '$info', '0', '$snap', '$insta', '$user', '$bg', '$discord')";
if ($conn->query($sql) === TRUE) {
echo "New card created!";
} else {
echo "There was an error";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="main.css">
<title>Personal cards for your social media or business | SocialCard</title>
</head>
<body>
<style>
.white {
color: white !important;
}
</style>
<div class="jumbotron">
<div class="container text-center">
<h1 class="big">Cards</h1><br>
<?php
$sql3 = "SELECT * FROM cards WHERE user = '$user'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0) {
//output cards
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $img; ?>">
</div>
</div>
</div>
</div>
<?php
}
}
?>
<br>
<?php echo $_SESSION["user"]; ?>
<hr>
<div class="card">
<div class="card-body text-center">
<h4>Card Name:</h4>
<form action="" enctype="multipart/form-data" method="post">
<br>
<input type="text" name="cardname">
<br>
<br>
<h4>Profile Image:</h4>
<input type="file" name="img">
<br>
<br>
<h4>Short info:</h4>
<input type="text" name="description">
<br>
<br>
<h4>Instagram link:</h4>
<br>
<input type="text" name="insta">
<br>
<br>
<h4>Snapchat link:</h4>
<br>
<input type="text" name="snap">
<br>
<br>
<h4>Discord Tag:</h4>
<br>
<input type="text" name="discord">
<br>
<br>
<h4>Background Color:</h4>
<br>
<input type="text" name="bg" placeholder="#hexcode">
<br>
<br>
<h4>Unique Id:</h4>
<br>
<input type="text" placeholder="Create One :), remember it" name="code" required>
<br>
<br>
<button type="submit" name="submit" class="btn btn-lg btn-primary">Create Card</button>
<p>To get to your card go to: social-card.pw/view.php?code=youruniqueid</p>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="card bg-dark">
<div class="card-content white">
<h1 class="text-center font1">Purchase Premium</h1>
<p class="text-center">Nothing here yet</p>
<script data-cfasync='false' type='text/javascript' src='//p258030.clksite.com/adServe/banners?tid=258030_546328_0&type=footer&size=37'></script>
</div>
</div>
</div>
</body>
</html>
This is my current php and html code, I must of made a small error because I everytime I go to view it the only thing that shows on my screen is the jumbotron at the top with the test "card" inside it, please help me! I'm sure its just a small error that I cant find out the answer to.
Im assuming its the php code, if anyone can help that would be great.
Assuming that your query is actually retrieving the cards, the display isn't fetching the image from the returned result...
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $img; ?>">
</div>
</div>
</div>
</div>
<?php
}
Using $img for the image isn't using the data from $row.
You should have something like...
echo $row['image'];
I'm also unsure if there is an extra </div> in the loop, you may need to move the last </div> outside the loop, but check this with the generated source.
Place the session_start() at the first line of page, i.e.:
session_start();
include ("db.php");
session_start(); must be started before any other line or operation.
<div class="jumbotron">
<div class="container text-center">
<h1 class="big">Cards</h1><br>
<?php
$sql3 = "SELECT * FROM cards WHERE user = '$user'";
$result3 = $conn->query($sql3);
if($result3->num_rows > 0) {
//output cards
while($row = $result3->fetch_assoc()) {
?>
<div class="col-sm-4">
<div class="card">
<div class="card-img-top">
<img alt="" src="pics/<?php echo $row['image']; ?>">
</div>
</div>
</div>
<?php
}
}
?>
Check all closing div
How to order divs side by side and centered when get datas from database in php and css ?
php and html codes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/normalize.css">
</head>
<body>
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="cards">
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
</div>
<?php }?>
</body>
</html>
css style codes
body {
background-color:#282828;
}
a{
text-decoration: none;
}
.cards{
text-align: center;
font-size: 0;
}
.card{
margin: 0 10px;
width: 250px;
text-align: left;
display: inline-block;
font-size: medium;
}
.card-img{
width: 250px;
margin-bottom: -5px;
}
.card-title{
background-color: #FFFCF5;
width: 240px;
padding:5px;
margin-bottom: 15px;
color: #282828;
}
.card-title>p>a{
color: #00BFA5;
}
my page looks like this:
but I want to those pictures order side by side
I couldn't that. How could I do?
Thank you
You got .cards inside you while loop, take it out:
<body>
<div class="cards">
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
<?php }?>
</div>
</body>
The reason your code doesnt work, is because .card is inline-block which will place multiple card nexto eachother, but because you look the .cards (note the S) as well, you wrap each item in a div. A div is a block element, which means it'll take up one whole row, the next element will fall below it.
For each row from database you parse, you will have this following output:
`
<div class="cards">
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
</div>
`
So, all you have to do is to have the cotainer outside the while loop, like this:
`
<div class="cards">
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
<?php }?>
</div>
`
I know it's not exactly what you want, but try :
cards { display : flex ; flex-direction : row ; justify-content : space-between }
/ ! \ Doesn't work on IE8 and previous
I have problem with my (made with tutorial) PHP comment box.
The problem is this number 1. I think that problem is in last code, but as I am beginner I don't know where is problem.
I'm posting all 3 php files without header and footer file.
PrtSc of problem on page
Source code in chrome of page
This is full code in php....
First php file
<?php
$title = "FilmoviRecenzije";
$content = '
<img src="Slike_filmovi/novo_Mockingjay2.jpg" class="imgLeft"/>
<h2>The Hunger Games: Mockingjay - Part 2 (2015)</h2>
<p><i>"Žanr: Avantura, Znanstvena fantastika"</i></p>
<p>Režija: Francis Lawrence<p>
<h4>
U grand finalu spektakularne kino-hit franšize Igre gladi Katniss Everdeen (Jennifer Lawrence),
nakon što je postala vođa masovne pobune potlačenih, zajedno sa Distriktom 13 pokreće
sveopću revoluciju protiv autokratskog Kapitola. Katniss nastavlja svoju ulogu heroja
koji se u nevjerojatnoj bitci za preživljavanje bori za svoj narod!
</h4>
<dev class="videoCenter">
<iframe width="720" height="405" src="https://www.youtube.com/embed/n-7K_OjsDCQ" frameborder="0" allowfullscreen></iframe>
</dev>
';
include ('Template_Mockingjay2.php');
?>
Next file which is connected through "include" is:
<?php include('Header.php'); ?>
<div id="wrapper">
<div id="banner">
</div>
<nav id="navigation">
<ul id="nav">
<li>Početna </li>
<li>Novi Filmovi</li>
<li>Kontakt</li>
</ul>
</nav>
<div id="content_area">
<?php echo $content; ?>
</div>
<div id="sidebar">
<?php echo include('novo_Mockingjay2_komentar.php'); ?>
</div>
<?php include ("Footer.php"); ?>
And last file for Mysql, same included is:
<?php
mysql_connect("localhost","root","");
mysql_select_db("db_komentari");
if (isset($_POST['Ime']) && isset($_POST['Komentar'])){
// $Ime = isset($_POST['Ime']) ? $_POST['Ime'] :
$Ime = $_POST['Ime'];
$Komentar = $_POST['Komentar'];
$submit = $_POST['submit'];
$dbLink = mysql_connect("localhost","root","");
if($submit)
{
if($Ime&&$Komentar)
{
$insert=mysql_query("INSERT INTO novo_mockingjay2 (Ime,Komentar) VALUES ('$Ime','$Komentar') ");
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=novo_Mockingjay2.php'>";
}
else
{
echo "Molim Vas ispunite oba polja";
}
}
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Komentari</title>
<center>
<form action="novo_Mockingjay2.php" method="POST">
<table>
<tr><td>Ime: <br><input type="text" name="Ime"/></td></tr>
<tr><td colspan="2">Komentar: </td></tr>
<tr><td colspan="5"><textarea name="Komentar" rows="1" cols="18"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Objavi"></td></tr>
</table>
</form>
<?php
$dbLink = mysql_connect("localhost","root","");
$getquery=mysql_query("SELECT * FROM novo_mockingjay2 ORDER BY ID DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$ID=$rows['ID'];
$Ime=$rows['Ime'];
$Komentar=$rows['Komentar'];
echo $Ime . ':<br/>' . $Komentar . '<br/>' . '<br/>' . '<hr size="4"/>';}
?>
Thank You in Advance!
As include language construct returns 1 on successful file including - this value is passed to your echo, so line:
echo include('novo_Mockingjay2_komentar.php');
means - include file, execute it and echo the result of inclusion. As result is 1 - it's echo'ed.
Change it to:
include('novo_Mockingjay2_komentar.php'); // without echo
I have the content:
<html>
<body>
<div class="another div">
other content
</div>
<div class="fck_detail width_common">
<p class="Normal">
Some text 1.
</p>
<p class="Normal">
Some text 2.
</p>
<div style="text-align:center;">
<div class="embed-container">
<div id="video-18574" data-component="true" data-component-type="video" data-component-value="18574" data-component-typevideo="2"></div>
</div>
</div>
<p class="Normal">
Some text 3.
</p>
<p class="Normal">
Some text 4.
</p>
</div>
</body>
</html>
I use the function below to get content of 'div class="fck_detail width_common"'
function get_content_by_tag($content, $tag_and_more, $include_tag = true){
$p = stripos($content,$tag_and_more,0);
if($p==false) return "";
$content=substr($content,$p);
$p = stripos($content," ",0);
if(abs($p)==0) return "";
$open_tag = substr($content,0,$p);
$close_tag = substr($open_tag,0,1)."/".substr($open_tag,1).">";
$count_inner_tag = 0;
$p_open_inner_tag = 1;
$p_close_inner_tag = 0;
$count=1;
do{
$p_open_inner_tag = stripos($content,$open_tag,$p_open_inner_tag);
$p_close_inner_tag = stripos($content,$close_tag,$p_close_inner_tag);
$count++;
if($p_close_inner_tag!=false) $p = $p_close_inner_tag;
if($p_open_inner_tag!=false){
if(abs($p_open_inner_tag)<abs($p_close_inner_tag)){
$count_inner_tag++;
$p_open_inner_tag++;
}else{
$count_inner_tag--;
$p_close_inner_tag++;
}
}else{
$count_inner_tag--;
if($p_close_inner_tag>0) $p_close_inner_tag++;
}
}while($count_inner_tag>0);
if($include_tag)
return substr($content,0,$p+strlen($close_tag));
else{
$content = substr($content,0,$p);
$p = stripos($content,">",0);
return substr($content,$p+1);
}
}
then I try
echo get_content_by_tag($content, '<div class="fck_detail width_common">');
It only return:
<div class="fck_detail width_common">
<p class="Normal">
Some text 1.
</p>
<p class="Normal">
Some text 2.
</p>
<div style="text-align:center;">
<div class="embed-container">
<div id="video-18574" data-component="true" data-component-type="video" data-component-value="18574" data-component-typevideo="2"></div>
</div>
</div>
missing the DIV with content "some text 3" and "some text 4"
who can tell me what's wrong?
One way to do this is through PHP Simple HTML DOM Parser
$str = '
<html>
<body>
<div class="another div">
other content
</div>
<div class="fck_detail width_common">
<p class="Normal">
Some text 1.
</p>
<p class="Normal">
Some text 2.
</p>
<div style="text-align:center;">
<div class="embed-container">
<div id="video-18574" data-component="true" data-component- type="video" data-component-value="18574" data-component-typevideo="2"></div>
</div>
</div>
<p class="Normal">
Some text 3.
</p>
<p class="Normal">
Some text 4.
</p>
</div>
</body>
</html>
';
$html = str_get_html($str);
echo $html->find("div[class='fck_detail width_common']",0)->innertext;
Try using this library : http://sourceforge.net/projects/simplehtmldom/
You can get your data in the following way
$url="www.yoururl.html";
$html = new simple_html_dom();
$html = file_get_html($url);
$data = $html->find('.fck_detail',0);
or
$html = str_get_html($str);
$data = $html->find("div[class='fck_detail width_common']",0)->innertext;
Now i dont know if this is simple or hard. If its just css or php code i need
But basically i have posting system and users can comment on posts. In the comments page it shows orginal post and one users have left (the comments)
I had one in there and this was fine but i added another and it looked like this...
[1]: http://i.stack.imgur.com/2fIXd.jpg
As you can see its completly different! Heres my code for it...
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("test");
echo "<a href='Untitled9.php'>Go Back...</a>";
?>
<br/><br/>
<div class="message">
<?php
$sql = mysql_query("SELECT * FROM threads WHERE id = '".
mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r['posted']); echo "".$r['author']." $posted"; ?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo "".$r['message'].""; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<div class="message2"><?php echo " ".$r['message'].""; ?></div>
<?php echo "Likes: ".$r['votes_up']." "; echo "Dislike: ".$r['votes_down']."";>
</div>
<br/>
<hr width="725px">
<?php
echo "<h3>Replies...</h3>"; ?>
<div class="message"><?php
$sql = mysql_query("SELECT * FROM replies WHERE thread = '".
mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
$posted = date("jS M Y h:i",$r['posted']); echo "".$r['author']." $posted"; ?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo "".$r['message'].""; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<div class="message2">
<?php echo " ".$r['message']."" ; } ?> </div>
</div>
<hr width="725px">
<form action="newreply.php" method="POST">
Your Name: <input type="text" name="author">
<input type="hidden" value="<?php echo $_GET['id']; ?>" name="thread"><br>
Message:<br><textarea cols="60" rows="5" name="message"></textarea><br>
<input type="submit" value="Post Reply">
</form>
The code looks really messy on here. I tried editing but couldnt get much better.
So bascially what i want to know is how do i prevent this (the overlapping) from happening?
Edit * CSS
.message {
width: 500px;
color: black;
background: white;
padding:8px;
border:1px solid white;
margin:5px auto;
-moz-border-radius:8px;
}
.message2 {
background-color: grey;
}
It looks to me as though everything is posting inside the second php function but i have some code pretty much the same for just the individual post and this displays normally i.e. as many as i want. Im just wondering is there something i need to add/change
Wrong (Your code):
<?php echo " ".$r['message']."" ; } ?> </div>
</div>
Correct:
<?php echo " ".$r['message']."" ; ?> </div>
</div>
<?php } ?>
You were opening multiple DIVs in your while loop but only closing two.
Similarly to Cobra_Fast's reply, it seems that the positioning of your divs seemed to be causing the problem, and also the position of your while loop.
Try replacing the replies section with the following and let me know if it is any better.
<?php
echo "<h3>Replies...</h3>";
$sql = mysql_query("SELECT * FROM replies WHERE thread = '".mysql_real_escape_string($_GET['id']) . "'") or die(mysql_error());
while($r = mysql_fetch_array($sql)) {
?>
<div class="message">
$posted = date("jS M Y h:i",$r['posted']);
echo $r['author']." ".$posted;
?>
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" data-text="<?php echo $r['message']; ?>">
Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</div>
<div class="message2">
<?php
echo " ".$r['message'];
?>
</div>
<?php
}
?>