tags:

views:

15

answers:

1

I currently have this code use for printing a table in mysql database , but there's a problem, the print button is also shown when I print the table. Do you know of any alternative or even a vb.net code that will print what is currently on the web browser in vb.net(the one being dragged from the toolbox used to view web pages or php files).

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("hospital", $con);

$result = mysql_query("SELECT * FROM t2 WHERE NURSE='{$_POST["nurse"]}'");

echo "<font='2'><b>ST. CATHERINE HOSPITAL</br> </font>";
 echo "<font='1'>CENTRAL EAST BANGAR LA UNION</b></font>";
echo "<table border='1'>
<tr>
<th>HospNum</th>
<th>RoomNum</th>
<th>LastName</th>
<th>FirstName</th>
<th>MidName</th>
<th>Address</th>
<th>TelNum</th>
<th>Nurse</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
   echo "<tr>";
  echo "<td>" . $row['HOSPNUM'] . "</td>";
  echo "<td>" . $row['ROOMNUM'] . "</td>";
    echo "<td>" . $row['LASTNAME'] . "</td>";
      echo "<td>" . $row['FIRSTNAME'] . "</td>";
        echo "<td>" . $row['MIDNAME'] . "</td>";
          echo "<td>" . $row['ADDRESS'] . "</td>";
           echo "<td>" . $row['TELNUM'] . "</td>";
            echo "<td>" . $row['NURSE'] . "</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

<form>
<input type="button" value="Print" onClick="window.print();" /> 
</form>
+1  A: 

You can use a specialised style for the print media, so that it will hide the button when the page is rendered for printing:

<style type="text/css">

@media print {

    input[type=button] { display: none; }

}

</style>
Guffa
+1. However, if I understand the question correctly, he is viewing the web page in a `WebBrowser` control in a VB.NET winforms app. In that case, using `input[type=button]` might be problematic, as the control uses Internet Explorer for rendering.
Jørn Schou-Rode
@Jørn: Good point. Adding a class or an id to the button and use that to target it from the css would be supported by older versions of Internet Explorer too.
Guffa
what do you mean problematic?
@user225269: Problematic in the way that it's not supported by Internet Explorer 6 or earlier.
Guffa