ezpdf - how to display a table which is already displayed on a webpage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rukshilag
    New Member
    • Apr 2010
    • 1

    ezpdf - how to display a table which is already displayed on a webpage

    i have a search page - here is the html
    Code:
    <html>
    <head>
    <style type="text/css">
    
    .up {
    float:right;
    background-color:#1b5b88;
    border:2px solid;
    padding:4px;
    color:white;
    }
    
    .over{
    float:right;
    background-color:#1b5b88;
    border:4px solid;
    border-color:#CEE3F6;
    padding:2px;
    color:white;
    }
    
    #blutable td,th{
    border:2px solid;
    border-color:white;
    padding:5px;
    }
    
    tr.odd{
    background-color:#CEE3F6;
    }
    
    tr.even{
    background-color:#E0ECF8;
    }
     
    </style>
    <script type="text/javascript" src="http://localhost/drupal/jquery.js"></script>
    
    <script type="text/javascript">
    
    
    //AJAX FUNCTION TO GET RESULTS FROM PHP SEARCH PAGE
    
    function ajaxsearch(){
    
    //Taking values from the form and assigning into variables
    var name=$("#name").val();
    var uni=$("#uni").val();
    var dept=$("#dept").val();
    var gen=$("#gen").val();
    var course=$("#course").val();
    var dofcourse=$("#cd").val();
    
    //Assigning radio button values into variables
    if (document.f1.cs[0].checked==true){
    var v="yes";
    }
    else if (document.f1.cs[1].checked==true){
    var v="no";
    }
    else if (document.f1.cs[2].checked==true){
    var v="cur";
    }
    else if(document.f1.cs[3].checked==true){
    var v="";
    }
    
    if (document.f1.gen[0].checked==true){
    var g="Male";
    }
    else if (document.f1.gen[1].checked==true){
    var g="Fem";
    }
    else if (document.f1.gen[2].checked==true){
    var g="";
    }
    
    //Ajax get request
    $.get("http://localhost/drupal/samsearch.php", { name: name, course: course, course_date: dofcourse, cs: v, uni: uni, dept: dept, gen: g},
       function(data){
         //alert("Data Loaded: " + data);
    document.getElementById("show").innerHTML=data;
       });
    return false;
    }
    
    
    function printfunc(result){
    //window.location("pdf.php?data=$result");
    var rslt = result ;
    var qstring = '?result='+rslt;
    window.location("http://localhost/drupal/pdf.php" +qstring);
    }
    
    
    
    
    //FUNCTION TO DIRECT USER TO EDIT PAGE 
    function editer(id){
    
    //Taking values from the form and assigning into variables
    var idn = document.getElementById("cpid_" + id).innerHTML;
    var crs = document.getElementById("course_" + id).innerHTML;
    var crsd = document.getElementById("coursed_" + id).innerHTML;
    
    //Building query string for get request
    var queryString = "?name=" + idn + "&course=" + crs + "&course_date=" + crsd;
    
    //Redirect using query string
    var location="http://localhost/drupal/node/3" + queryString;
    var newwin;
    newwin=window.open(location);
    newwin.focus();
    	
    
    }
    
    
    
    
    
    /*function Clickheretoprint()
    {
    var content=document.getElementById("show").innerHTML;
    if(content.length<30){
    alert("No Results to Print");
    }
    else{
      var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
      disp_setting+="scrollbars=yes,width=1200, height=1000, left=100, top=25";
      var content_vlue = document.getElementById("show").innerHTML;
     
      var docprint=window.open("","",disp_setting);
       docprint.document.open();
       docprint.document.write('<html><head><title>Print Results</title>');
       docprint.document.write('</head><body style="width:620px; height:100%;" table border="2" width="100%" id="blutable" onLoad="self.print()"><center>');        
       docprint.document.write(content_vlue);         
       docprint.document.write('</center></body></html>');
       docprint.document.close();
       docprint.focus();
    }
    }*/
    
    </script>
    
    </head>
    
    <strong>SEARCH</strong><br/>
    <div>
    <form id="myForm" name="f1" style="background-color:#F2F2F2; border:1px solid; border-color:#084B8A;
    width:98%; padding:10px;" onSubmit=" return ajaxsearch()">
    <table>
    <tr>
    <td>Name:</td><td width="100%"><input type="text" size="60" name="name" id="name"/></td>
    </tr>
    
    <tr>
    <td>Gender:</td>
    <td width="500">
    <input type="radio" name="gen" value="male">MALE</radio> 
    <input type="radio" name="gen" value="female">FEMALE</radio> 
    <input type="radio" name="gen" value="either" checked>EITHER</radio> 
    </td>
    </tr>
    
    <tr>
    <td>University:</td><td width="150"><input type="text" size="50" name="uni" id="uni"/></td>
    <td>Department/Faculty:</td><td width="150"><input type="text" size="50" name="dept" id="dept"/></td>
    </tr>
    
    <tr>
    <td>Course:</td>
    <td>
    <input type="text" name="course" id="course"/>
    Date of Course:
    <input type="text" name="cd" id="cd"/>
    </td>
    <td>Completed Successfully:</td>
    <td width="500">
    <input type="radio" name="cs" value="yes">YES</radio> 
    <input type="radio" name="cs" value="no">NO</radio> 
    <input type="radio" name="cs" value="cur">CURRENT</radio> 
    <input type="radio" name="cs" value="all" checked>ALL</radio> 
    </td>
    </tr>
    
    
    </table>
    </div>
    
    <input type="reset" value="RESET" name="find" style="float:right;" class="up"onmouseover="this.className='over'"onmouseout="this.className='up'"/>
    
    <input type="submit" value="FIND" name="find" class="up"onmouseover="this.className='over'"onmouseout="this.className='up'"/>
    
    <br/>
    </form>
    
    <div id="show" style='width:100%; height:100%; overflow:auto; border:1px solid; border-color:#084B8A;'>
    </div>
    
    
    </html>

    here is the search.php
    Code:
    <?php
    
    //access incoming name, id or radio button values
    $cs = $_GET['cs'];
    $name=$_GET['name'];
    $uni=$_GET['uni'];
    $dept=$_GET['dept'];
    $course=$_GET['course'];
    $cd=$_GET['course_date'];
    $gen=$_GET['gen'];
    
    $con=mysql_connect("localhost", "root", "") or die ("couldnt connect");
    mysql_select_db("sdc_cpds") or die ("couldnt select");
    
    //search query
    $result=mysql_query("SELECT * FROM course_participant WHERE name LIKE '%$name%' AND gender LIKE '$gen%' AND university LIKE '%$uni%' AND facdept LIKE '%$dept%'  AND course LIKE '%$course%' AND course_date LIKE '%$cd%' AND completion LIKE '%$cs%' UNION SELECT * FROM past_participant WHERE name LIKE '%$name%' AND gender LIKE '%$gen%' AND university LIKE '%$uni%' AND facdept LIKE '%$dept%'  AND course LIKE '%$course%' AND course_date LIKE '%$cd%' AND completion LIKE '%$cs%' ORDER BY name");
    $num_rows=mysql_num_rows($result);
    
    echo "<b>$num_rows</b> results found<br>"; 
    //echo "<INPUT TYPE='image' SRC='http://localhost/drupal/printwebpagepdf.gif' OnClick='clickPrint()'>";
    //display results(search results table)
    if($num_rows >0) {
    
    echo "<div style='width:620px; height:100%;'>";
    echo "<table border='2' width='100%' id='blutable'>";
    echo "<tr style='background-color:#A9D0F5'><th></th><th>Name</th><th>Address</th><th>Contact No</th><th>Email</th><th>Gender</th><th>Age</th><th>Marital Status</th><th>University</th><th>Fac/Dept</th><th>Course</th><th>Course Date</th><th>Reg. Date</th><th>Completion</th></tr>";
    
    $i=1;
    
    while($row = mysql_fetch_array( $result )) {
    
    $r = fmod($i,2);
    if($r=="1"){
    $rowclass="odd";
    }
    else{
    $rowclass="even";
    }
    
    echo "<tr class='$rowclass'>";
    //echo "<td><input type='submit' value='EDIT' onclick='editer($i)' style='width:50px; height:25px background;'/></td>";
    
    echo "<td style='padding:1px;' valign='bottom'><INPUT TYPE='image' SRC='http://localhost/drupal/more.png' onclick='editer($i)' style='width:25px; height:25px;'/></td>";
    
    
     echo "<td nowrap><div id='cpid_$i'>";echo $row['name'];"</div></td>";
     //echo "<td><div id='cpid_$i'>";echo $row['nic'];echo "</div></td>";
     echo "<td nowrap>";echo $row['res_address'];echo "</td>";
     echo "<td>";echo $row['cont_no'];echo "</td>";
     echo "<td>";echo $row['email'];echo "</td>";
     echo "<td>";echo $row['gender'];echo "</td>";
     echo "<td>";echo $row['age'];echo "</td>";
     echo "<td>";echo $row['marital_stat'];echo "</td>";
     echo "<td nowrap>"; echo $row['university']; echo "</td>";
     echo "<td nowrap>"; echo $row['facdept']; echo "</td>";
     echo "<td nowrap><div id='course_$i'>"; echo $row['course']; echo "</div></td>";
     echo "<td nowrap><div id='coursed_$i'>"; echo $row['course_date']; echo "</div></td>";
     echo "<td nowrap>"; echo $row['reg_date']; echo "</td>";
     echo "<td>";echo $row['completion']; echo "</td>";
    echo "</tr>";
    
    $i++;
    }
    echo "</table>";
    echo "</div>";
    
    echo "<form action='http://localhost/drupal/pdf.php' name='print'>";
    echo "<input type='submit' value='PRINT RESULTS' name='pr' style='float:right;' class='up'onmouseover='this.className='over''onmouseout='this.className='up' OnClick='printfunc(result)'/>";
    echo "</form>";
    }
    
    //close connection
    mysql_close($con);
    
    
    ?>
    and this is teh pdf.php page
    Code:
    <?php
    # Catch the posted data, validate by getting rid of > and <
    $header =$_POST['header'];
    # Replace > and < with a blank space
    $header = str_replace('<','',$header);
    $header = str_replace('>','',$header);
    $body =$_POST['body'];
    # Replace > and < with a blank space
    $body = str_replace('<','',$body);
    $body = str_replace('>','',$body);
    
    # Include the file that does all of the work
    include ('class.ezpdf.php');
    
    # Start a new PDF file
    $pdf =& new Cezpdf();
    
    # Select the font we'll be using. There are more fonts in the zip file.
    $pdf->selectFont('./fonts/Helvetica.afm');
    
    # include the header, then move down a couple of lines, font size 25
    # justification centered (centred if you're from the UK)
    $pdf->ezText($header . "\n\n",25,array('justification'=>'centre'));
    
    # include the body after moving down 7 lines to get under the pic.
    # Font size 16, justification centered.
    $pdf->ezText("\n\n\n\n\n\n\n" . $body,16,array('justification'=>'centre'));
    
    //inside
    $pdf->ezText('Hello World!',20);
    //--------------------------------------------------
    // you will have to change these to your settings
    $host = 'localhost';
    $user = 'root';
    $password = '';
    
    $database = 'sdc_cpds';
    
    $query = 'SELECT * FROM course_participant';
    //--------------------------------------------------
    /*
    $data = array(  array('Name'=>1,'Address'=>'gandalf','Contact Number'=>'wizard','Email'=>'wizard','Gender'=>'wizard','Age'=>'wizard','Marital Status'=>'wizard','University'=>'wizard','Fac/Dept'=>'wizard','Course'=>'wizard','Course Date'=>'wizard','Reg Date'=>'wizard') );
    */
    //$pdf->ezTable($data);
    // open the connection to the db server
    $link = mysql_connect($host,$user,$password);
    // change to the right database
    mysql_select_db($database);
    // initialize the array
    $data = array();
    // do the SQL query
    $result = mysql_query($query);
    // step through the result set, populating the array, note that this could also have been written:
    // while($data[] =  mysql_fetch_assoc($result)) {}
    while($data[] =  mysql_fetch_array($result, MYSQL_ASSOC)) {}
    // make the table
    $pdf->ezTable($data);
    
    // do the output, this is my standard testing output code, adding ?d=1
    // to the url puts the pdf code to the screen in raw form, good for checking
    // for parse errors before you actually try to generate the pdf file.
    if (isset($d) && $d){
      $pdfcode = $pdf->output(1);
      $pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode));
      echo '<html><body>';
      echo trim($pdfcode);
      echo '</body></html>';
    } else {
      $pdf->stream();
    }
    
    
    
    #create the pdf and stream it to the page
    $pdf->output();
    $pdf->ezStream();
    ?>

    i want to know how i can directly generate a pdf of the resulting table in the search page instead of running a separate query in the pdf.php page?

    How am i to do this? Please Help
Working...