...

View Full Version : javascript print not decoding php variables



johnniegee
07-31-2010, 09:21 PM
Hi,
I am trying to print a hard copy from a database using php and javascript.

this is my console display:



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:


Uni ID Name
|||||||| |||||||||||||||||||||||| 0 DHYH 2 |1 HOQD

The php/html code is:



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:



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.

semiSkim
08-01-2010, 12:18 AM
try: $row['username']
and not: $row[username]

johnniegee
08-01-2010, 02:07 PM
tried 'username' and "username" but it gives a syntax error. thanks anyway

semiSkim
08-01-2010, 02:23 PM
tried 'username' and "username" but it gives a syntax error. thanks anyway

Try this:



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/>
';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum