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.

Gopal Joshi
  • 2,350
  • 22
  • 49
Ripon
  • 81
  • 2
  • 8
  • 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 http://www.php.net/manual/en/book.mysqli.php – Reflic Apr 13 '14 at 09:18
  • 1
    possible duplicate of [PHP PDF Generator Advice](http://stackoverflow.com/questions/12350265/php-pdf-generator-advice) – Imran Apr 13 '14 at 09:26

2 Answers2

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)

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"] . "'";
empiric
  • 7,825
  • 7
  • 37
  • 48
Ivica Hrg
  • 26
  • 4