Loop a multidimensional array and only print two specific column values per row

Using a foreach loop without a key: foreach($array as $item) { echo $item[‘filename’]; echo $item[‘filepath’]; // To know what’s in $item echo ‘<pre>’; var_dump($item); } Using a foreach loop with a key: foreach($array as $i => $item) { echo $array[$i][‘filename’]; echo $array[$i][‘filepath’]; // $array[$i] is same as $item } Using a for loop: for ($i … Read more

Javascript window.print() in chrome, closing new window or tab instead of cancelling print leaves javascript blocked in parent window

It looks like the problem had been resolved with the latest Chrome update… I’m running the Chrome Version 36.0.1964.4 dev-m. I was limited too warning the user from closing print preview window by doing the following: if(navigator.userAgent.toLowerCase().indexOf(‘chrome’) > -1){ // Chrome Browser Detected? window.PPClose = false; // Clear Close Flag window.onbeforeunload = function(){ // Before … Read more

Print a div content using Jquery

Some jQuery research has failed, so I moved to JavaScript (thanks for your suggestion Anders). And it is working well… HTML <div id=’DivIdToPrint’> <p>This is a sample text for printing purpose.</p> </div> <p>Do not print.</p> <input type=”button” id=’btn’ value=”Print” onclick=’printDiv();’> JavaScript function printDiv() { var divToPrint=document.getElementById(‘DivIdToPrint’); var newWin=window.open(”,’Print-Window’); newWin.document.open(); newWin.document.write(‘<html><body onload=”window.print()”>’+divToPrint.innerHTML+'</body></html>’); newWin.document.close(); setTimeout(function(){newWin.close();},10); }

Safe width in pixels for printing web pages?

As for a true “universal answer”, I can’t provide one. I can, however, provide a simple and definitive answer for some particulars… 670 PIXELS At least this seems to be a safe answer for Microsoft products. I read many suggestions, including 675, but after testing this myself 670 is what I came up with up. … Read more

how to print selected rows JTable

Seems to work okay for me… import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; public class TestPrint { public static void main(String[] args) { new TestPrint(); } public TestPrint() { EventQueue.invokeLater(new … Read more

Javascript Event Handler for Print

Different Style Sheets You can specify a different stylesheet for printing. <link rel=”stylesheet” type=”text/css” media=”print” href=”https://stackoverflow.com/questions/534977/print.css” /> <link rel=”stylesheet” type=”text/css” media=”screen” href=”main.css” /> One Style Sheet As kodecraft mentioned, you can also put the styles into the same file by using the @media block. @media print { div.box { width:100px; } } @media screen { … Read more

How to position the input text cursor in C?

If you are under some Unix terminal (xterm, gnome-terminal …), you can use console codes: #include <stdio.h> #define clear() printf(“\033[H\033[J”) #define gotoxy(x,y) printf(“\033[%d;%dH”, (y), (x)) int main(void) { int number; clear(); printf( “Enter your number in the box below\n” “+—————–+\n” “| |\n” “+—————–+\n” ); gotoxy(2, 3); scanf(“%d”, &number); return 0; } Or using Box-drawing characters: … Read more