Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript print not decoding php variables

    Hi,
    I am trying to print a hard copy from a database using php and javascript.

    this is my console display:

    Code:
    Uni ID  	                                  Name
    i1111111 ................................. Maeve O'Neill
    and this is the best I can make up from my keyboard as to the hard copy output:
    Code:
    Uni ID  	                                  Name
    |||||||| |||||||||||||||||||||||| 0 DHYH 2 |1 HOQD
    The php/html code is:

    Code:
    echo
    "<tr bgcolor=lightsteelblue>
    <th align=left><font face=\"Times\" size=\"3\">Uni ID</font></th>
    <th align=left><font face=\"Times\" size=\"3\">Name</font></th>
    </tr>
    ";
    
    echo 
    "<font face=\"courier\"size=\"3\"><tr><td>$row[username]</font></td>
     <font face=\"courier\"size=\"3\"><td>$row[forename]</font></td>
     <font face=\"courier\"size=\"3\"><td>$row[surname]</font></td><br/>	
    ";
    and the javascript is:

    Code:
    var display_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
    display_setting+="scrollbars=yes,width=750, height=600, left=100, top=25";
    
    var content_innerhtml = document.getElementById("printArea").innerHTML;
    var document_print=window.open("","",display_setting);
    document_print.document.open();
    document_print.document.write('<html><head><title>Print using javascript </title></head>');
    document_print.document.write('<body style="font-family:arial; font-size:16px;" onLoad="self.print();self.close();" >');
    document_print.document.write(content_innerhtml);
    document_print.document.write('</body></html>');
    document_print.print();
    document_print.document.close();
    return false;
    It is printing out the words I have given it but not the php variables.

    I can't for the life of me see where I am losing the encoding and I also can't find anything on web searches as I cannot copy the rubbish that is coming out to try a search on it :-(

    Any help would be appreciated,
    thanks.

  • #2
    Regular Coder
    Join Date
    Feb 2010
    Posts
    104
    Thanks
    5
    Thanked 3 Times in 3 Posts
    try: $row['username']
    and not: $row[username]

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    didn't work :-)

    tried 'username' and "username" but it gives a syntax error. thanks anyway

  • #4
    Regular Coder
    Join Date
    Feb 2010
    Posts
    104
    Thanks
    5
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by johnniegee View Post
    tried 'username' and "username" but it gives a syntax error. thanks anyway
    Try this:

    Code:
    echo '<tr><td><font face="courier" size="3">' . $row['username'] . '</font></td>
     <td><font face="courier" size="3">' . $row['forename'] . '</font></td>
     <td><font face="courier" size="3">' . $row['surname'] . '</font></td><br/>	
    ';


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •