4

I am new to PHP. I have completed some tasks for file saving/edit and view the data information from mysql table. I have found some code from web that can export mysql selected data to pdf. but it takes two steps.I need your help to get the information if any user click the record from view page(view.php) it will generate the pdf file of the selected reocrd from mysql table instead of going to next page. currently it is giving all the record output from mysql table instead of giving selected record output. I below is my code so far i have dome.

view.php

<?php
    include('ps_pagination.php');
$conn = mysql_connect('localhost','root','xyz');
if(!$conn) die("Failed to connect to database!");
$status = mysql_select_db('test', $conn);
if(!$status) die("Failed to select database!");
$sql = 'SELECT * FROM customer order by CustomerID DESC';


$pager = new PS_Pagination($conn, $sql, 10, 5);
$rs = $pager->paginate();
    $result = mysql_query("SELECT * FROM customer order by CustomerID DESC");
    while($row = mysql_fetch_array($rs))
        {

            echo '<td><div align="left">'.$row['CustomerID'].'</td>';
            echo '<td><div align="left">'.$row['Name'].'</div></td>';
            echo '<td><div align="left">'.$row['Email'].'</div></td>';
            echo '<td><div align="left">'.$row['CountryCode'].'</td>';
            echo '<td><div align="left">'.$row['Budget'].'</div></td>';

            echo '<td><div align="left">'.$row['Used'].'</div></td>';

            echo "<td><a href=\"php_pdf_mysql.php?CustomerID=$row[CustomerID]\"><img src='Printer.jpg' width='40' height='30'/></a></td>";
            echo '</tr>';
        }
    ?> 

php_pdf_mysql.php

// Load MySQL Data

$objConnect = mysql_connect("localhost","root","xyz") or die(mysql_error());

$objDB = mysql_select_db("test");

$strSQL = "SELECT * FROM customer";

$objQuery = mysql_query($strSQL);

$resultData = array();

for ($i=0;$i<mysql_num_rows($objQuery);$i++) {

    $result = mysql_fetch_array($objQuery);

    array_push($resultData,$result);

}

Your information is highly appreciated.

2
  • 2
    btw: You should use the mysqli extension instead of the deprecated mysql extension. The extension and its support will be dropped soon. For futher information look php.net/manual/en/book.mysqli.php Commented Apr 13, 2014 at 9:18
  • 1
    possible duplicate of PHP PDF Generator Advice Commented Apr 13, 2014 at 9:26

2 Answers 2

2
 <script type="text/javascript">
 function printpdf() 
 {
  myWindow=window.open("pdfwebpage.html");
   myWindow.close;  //optional, to close the new window as soon as it opens
}
  </script>

<body onload="window.print()"> 

(in body of the page)

Sign up to request clarification or add additional context in comments.

Comments

0

It seems to me that in php_pdf_mysql.php you should query database only for clicked record so you should replace

$strSQL = "SELECT * FROM customer";

with

$strSQL = "SELECT * FROM customer WHERE CustomerID='" . $_GET["CustomerID"] . "'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.