tek tek masaları yazdırmak?

2 Cevap php

I am getting values from a database and displaying in a table. Im trying to print the results as individual . Im using the below javascript

<script type="text/javascript">
function print_parent(element)
{
  element.parentNode.className = 'print';
  window.print();
  element.parentNode.className = '';
  return false;
}
</script>

I nasıl ben her sonucu her tablo lütfen yazdırabilirsiniz lütfen bana biraz bir great.can çalışır bütün sonuçlarını yazdırmak çalıştığınızda ben var sorun?

Aşağıda benim php kodu

$sql="select * from cisdb where pids LIKE '%$pids%'";
    $result=mysql_query($sql) or die(mysql_error());


    if (mysql_num_rows($result)==0) {
        echo '<b><center>There was no records !</center></b>'."<br>";
    }

    while ($row=mysql_fetch_array($result)) {
        $cat=str_replace('+', ' ', $row['category']);
print "<center>";
    print "<table width='472' border='1' align='center' class='noprint'>";
print "<tr>";
print "<td width='150'><div align='center'><a href='#' onclick='return print_parent(this)'>Print</a>
</div></td>";
print "<td width='150'><div align='center'><a href='process.php?mode=ed&id={$row['id']}'>Edit</div></td>";
print "<td width='150'><div align='center'><a href='process.php?mode=del&id={$row['id']}' onclick='return confirm('Are you sure you want to delete?')'>Delete</a></div></td>";
print "</tr>";
print "</table><br>";

print "<div id='divToPrint'>";      
print"<table width=700 style=height:900 border=1 cellpadding=1 cellspacing=1 bordercolor=#D6D6D6 class=sss title={$row['title']}>

  <tr>
    <td height=25 colspan=2 align=left valign=top><strong>Customer:{$row['name']}</strong></td>
    <td width=183 align=left valign=top><strong>Sales ID:{$row['said']} </strong></td>
    <td width=100 align=left valign=top><strong>Phone Cord. ID:{$row['pcid']}</strong></td>
    <td align=left valign=top><strong>Type:{$row['classtype']}</strong></td>
  </tr>
   <tr>
    <td height=25 colspan=2 valign=top><strong>Contact Name: </strong></td>
    <td colspan=2 valign=top><strong>Email:</strong></td>
    <td width=154 valign=top><strong>Phone:</strong></td>
  </tr
  <tr>
    <td height=15 colspan=5 valign=top><strong>Remarks:</strong></td>
  </tr>
  <tr>
    <td height=15 colspan=2 valign=top><strong>Date Added: </strong></td>
    <td valign=top><strong>Date Edited : </strong></td>
    <td colspan=2 valign=top><strong>Printed : </strong></td>
  </tr>  
</table></div><br>";
print "</center>";

        }

2 Cevap

Bu kodu, sopa ve yazdırmak istediğiniz herhangi bir öğe id = baskı koymak!

Bu jQuery kullanın:

$("#print")
                    .attr( "href", "javascript:void( 0 )" )
                    .click(
                        function(){
                            // Print the DIV.
                            $(".printable").print();

                            // Cancel click event.
                            return( false );
                        });

Ve bu dosyayı js:

    // Create a jquery plugin that prints the given element.
jQuery.fn.print = function(){
    // NOTE: We are trimming the jQuery collection down to the
    // first element in the collection.
    if (this.size() > 1){
        this.eq( 0 ).print();
        return;
    } else if (!this.size()){
        return;
    }

    // ASSERT: At this point, we know that the current jQuery
    // collection (as defined by THIS), contains only one
    // printable element.

    // Create a random name for the print frame.
    var strFrameName = ("printer-" + (new Date()).getTime());

    // Create an iFrame with the new name.
    var jFrame = $( "<iframe name='" + strFrameName + "'>" );

    // Hide the frame (sort of) and attach to the body.
    jFrame
        .css( "width", "1px" )
        .css( "height", "1px" )
        .css( "position", "absolute" )
        .css( "left", "-9999px" )
        .appendTo( $( "body:first" ) )
    ;

    // Get a FRAMES reference to the new frame.
    var objFrame = window.frames[ strFrameName ];

    // Get a reference to the DOM in the new frame.
    var objDoc = objFrame.document;

    // Grab all the style tags and copy to the new
    // document so that we capture look and feel of
    // the current document.

    // Create a temp document DIV to hold the style tags.
    // This is the only way I could find to get the style
    // tags into IE.
    var jStyleDiv = $( "<div>" ).append(
        $( "style" ).clone()
        );

    // Write the HTML for the document. In this, we will
    // write out the HTML of the current element.
    objDoc.open();
    objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
    objDoc.write( "<html>" );
    objDoc.write( "<body>" );
    objDoc.write( "<head>" );
    objDoc.write( "<title>" );
    objDoc.write( document.title );
    objDoc.write( "</title>" );
    objDoc.write( jStyleDiv.html() );
    objDoc.write( "</head>" );
    objDoc.write( this.html() );
    objDoc.write( "</body>" );
    objDoc.write( "</html>" );
    objDoc.close();

    // Print the document.
    objFrame.focus();
    objFrame.print();

    // Have the frame remove itself in about a minute so that
    // we don't build up too many of these frames.
    setTimeout(
        function(){
            jFrame.remove();
        },
        (60 * 1000)
        );
}

Bir masanızı sarın

<div class="printable">

Burada tablo

</div>

kullanarak yukarıda önerilen ve jquery kullanmak

$(".printable").print();