I want to create a PDF using HTML, PHP, and MySQL and I want a new page every time a new row is fetched and then generate a combined PDF for all the pages created.
How can I achieve this?
<?php
$count=0;
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con, "electricity");
$result = mysqli_query($con, "SELECT acct, name, address, amount FROM newtable");
while($row = mysqli_fetch_array($result))
{
?>
<html>
<body><pre>
श्री: <?php echo $row['name'];?><br>
पता: <?php echo $row['address'];?>
ACCNO :- <b><?php echo $row['acct'];?></b>
Amount : <b><?php $val=$row['amount']+25; echo $val;?></b>
</pre>
</body>
</html>
<?php
}
mysqli_close($con);
?>
I used FPDF many times and it allows you to do whatever you want. Have more info here for doc & download link : http://www.fpdf.org/?lang=en
Related
I have created a members.php page that connects to a database table. The table has the following fields: id, username, profile image.
The following PHP code displays the profile image for each user in rows of 6 and allows each image to be clickable.
<?php
// The code below will display the current users who have created accounts with: **datemeafterdark.com**
$result=mysql_query("SELECT * FROM profile_aboutyou");
$row1 = mysql_fetch_assoc($result);
$id = $row1["id"];
$_SESSION['id'] = $id;
$profileimagepath = $row1["profileimagepath"];
$_SESSION['profileimagepath'] = $profileimagepath;
$count = 0;
while($dispImg=mysql_fetch_array($result))
{
if($count==6) //6 images per row
{
print "</tr>";
$count = 0;
}
if($count==0)
print "<tr>";
print "<td>";
?>
<center>
<img src="<?php echo $dispImg['profileimagepath'];?>" width="85px;" height="85px;">
</center>
<?php
$count++;
print "</td>";
}
if($count>0)
print "</tr>";
?>
This is all great, however, when I click on the image that loads it re-directs me to: viewmemberprofile.php which is what it is supposed to do. But it always displays the same image with the same id value (i.e.) 150 no matter which image I click. What I would like to have happened is. If I click on an image with id 155 etc... it will display content for that image data field not consistently the same image data regardless of which image I click.
Your help and guidance would be greatly appreciated. Thank you in advance.
One thing that I forgot to mention is that I do use sessions so... when I am re-directed to the viewmemberprofile.php page I use the following code to aide in getting the data that I need from the table.
<?php
$id = $_SESSION['id'];
echo($id);
?>
<?php
echo('<br>');
?>
<?php
$profileimagepath = $_SESSION['profileimagepath'];
?>
<img src="<?php echo($profileimagepath);?>" width="50px;" height="50px;">
I have yet to impliment the suggested solution.
You need to pass the ID of the row to viewmemberprofile.php, e.g.:
<a href="viewmemberprofile.php?id=<?= $dispImg['profileimagepath'] ?>">
And viewmemberprofile.php needs to select that row from the DB:
SELECT * FROM profile_aboutyou WHERE id = $_GET['id']
The above SQL statement is pseudo-code; you need to write actual code to accomplish what it is describing, preferably using parameterized queries.
I've been working on this for four hours and I still have no clue, so I came here to seek help. I'm learning PHP and mySQL and one of the way I learn is to learn from open source projects. Today I'm trying to understand an open source project and I have some problems. Here is the link to the open source project: https://github.com/markpytel/Printstagram Basically, it has something like the following, let's call it profileinfo.php (name of this file is pretty deceiving, it is a page that shows images uploaded by different users)
<?php
$sql="SELECT pid,poster, pdate FROM photo WHERE poster='$myusername' OR pid
in (select pid from tag where taggee='$myusername') OR pid in (select pid
from ingroup natural join shared where username='$myusername' and username
!= ownername) ORDER BY pdate desc";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo "<hr>";
echo "Posted by: " . $row["poster"]. " Time: " . $row["pdate"]."<br>";
// pid is each photo's unique id in the database
$pidrow=($row["pid"]);
?>
</head>
<body>
<form action="listsingleREV.php?pidrow=<?php echo $pidrow; ?>" method="POST">
<input type="submit" id="pidrow" value="View this image" />
</form>
</body>
</html>
If you click on the button that says "view this image", image uploaded by users will appear. The first question I have is: What's the meaning of the question mark in the image src. I understand that there is a PHP tag in the img src, but I don't understand why there is a question mark between listsingleREV.php and pidrow.
listsingleREV.php looks like this:
<?php
session_start();
$pidrow=$_GET['pidrow'];
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("printstagram");
$sql = "SELECT pid FROM photo WHERE pid=$pidrow";
$result = mysql_query($sql);
?>
<?php
while($row = mysql_fetch_array($result)) {
?>
<img src="imageview.php?pid=<?php echo $row["pid"]; ?>" /><br/>
<?php
}
?>
imageview.php looks like this:
<?php
$conn = mysql_connect("localhost", "root", "");
mysql_select_db("printstagram") or die(mysql_error());
if(isset($_GET['pid'])) {
$sql = "SELECT image FROM photo WHERE pid=" . $_GET['pid'];
$result = mysql_query("$sql") or die("<b>Error:</b> Problem on Retrieving Image BLOB<br/>" . mysql_error());
$row = mysql_fetch_array($result);
header("content-type: image/jpeg");
echo $row["image"];
}
mysql_close($conn);
?>
Of course, if a user has to click on a button to see each image, it is very inconvenient. So I decide to give myself some practice and modify the code(it is Apache license so I can do it)such that images will be automatically presented on profileinfo.php without the need to click on a button. Since imageview.php and listsingleREV.php show the images, I tried to substitute the form in profileinfo.php with these two files. I worked on it for four hours without achieving my goal. Can someone tell me the correct way to show the images on profileinfo.php without the need to click on the button?
As it appears in imageview.pho the $row[pid] contain the link of your image in photo table so add this line to profileinfo.php under the while loop in the place you want it to display
<img src="<?php echo". $row["pid"]."; ?>">
I've searched hard to find a way to print the query of the code above into a HTML part, but i don't find anything. I saw that is possible to present the result by a HTML table using the fetch_assoc() of php. Below is the code, and on a global view the code is fine, because i test it on a full php page. But i need a solution to put it in HTML. Am i trying an impossible thing?
<?php
require_once('connconf.php');
$conn = mysqli_connect($server, $user, $pw, $bdname) or die ('Connection Error');
$sqlquery = "select ID_Vote from Votes where ID_Player = '1'";
if($result = mysqli_query($conn, $sqlquery)) {
$rowcount = mysqli_num_rows($result);
echo $rowcount; //this is the value i want to publish on a HTML <label>
}
?>
If you want to output the results in a table you could do like this:
print "<table>";
while($row = mysqli_fetch_assoc($result)) {
print "<tr><td>".$row['ID_Vote']."</td></tr>";
}
print "</table>";
The same goes if you just want to print the amount of rows:
print "<table>";
print "<tr><td>".$rowcount."</td></tr>";
print "</table>";
Another way of doing it could be to end php:
<?
// Some code
?>
<table>
<tr>
<td><?=$rowcount;?></td>
</tr>
</table>
<?
// More php
?>
You can have a read here
Guys i found the solution to my problem, all the query was ok like i said. But the extension of my webpage was .HTML and when i change it to .php it worked. Now i got the website running with HTML and php code using a .php extension instead .html
Thanks for your attention.
I have images stored in my database i want to load them in the browser i have two pages one of them is
show_picture.php and the other one is get_image.php my image contents does not load in the browser and it is like that the image has been moved or something but the images are stored in database so here is my code
<?php include("includes/student_session.php");?>
<?php confirm_logged_in();?>
<html>
<body>
<?php include("includes/connection.php");?>
<?php
if (isset($_SESSION['exam_id']) and isset($_SESSION['register_id'])){
$exam_id=mysqli_real_escape_string($cnn,$_SESSION['exam_id']);
$query="select question_id from questions where exam_id={$exam_id} order by page_number asc";
$result=mysqli_query($cnn,$query);
if($result){
while ($row=mysqli_fetch_array($result)){
echo "<img src=\"get_image.php?id={$row['question_id']}\"/>";
}
}
}
?>
</body>
</html>
and this is my get_image.php
<?php include("includes/connection.php");?>
<?php
$question_id=$_REQUEST['id'];
$query="select question from questions where question_id={$question_id} limit 1";
$result=mysqli_query($cnn,$query);
$row = mysqli_fetch_array($result);
//mysql_close($cnn);
header("Content-type: image/jpg");
echo $row['question'];
?>
I am wondering what i am missing
I am trying to position the data pulled from my mysql database using the following php code on my webpage;
<?php
require "connect.php";
$query = "select * from item LIMIT 0, 1";
$result = #mysql_query($query, $connection)
or die ("Unable to perform query<br>$query");
?>
<?php
while($row= mysql_fetch_array($result))
{
?
//call each item from the database, and nest in div or html table
<?=$row['item']?>
<?=$row['description']?>
<?=$row['brand']?>
When I view the webpage it creates the row for each item however each field is empty?
The conection to the database is fine as I ran another piece of code which simply displayed all the info in 1 block. However this is not what I want I want to be able to position each item where I want it on the site.
I wrote this when I had php version 4.1 running on IIS I am now running the latest version of php 5 and after doing some reading it says there are chnages in the syntax including global variables disabled by default so not sure if this is the issue?
try:
<?php echo $row['item'] ?>
<?php echo $row['description'] ?>
<?php echo $row['brand'] ?>
I believe the <?= ?> syntax is normally disabled by default.
The following will also show a dump of you $row array, so you can make sure that it actually contains data
<?php print_r($row); ?>
Good luck!
Sorttag maybe no enabled, try :
<?php echo $row['item']; ?>
<?php echo $row['description']; ?>
<?php echo $row['brand']; ?>