Guys I need to print tne content of my div named "content" my code will only work if their is only one div named "content" but in my case I have a lot of div with same ID because I iterated it along with the codes from mysql, can anybody help me? this is my qhole code:

<?php
session_start();
include("database.php");
if (isset($_SESSION['username']))
{
include("database.php");


?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Blood Chemistry</title>
<link rel="shortcut icon" href="images/bernardino.ico" />
<link rel="stylesheet" type="text/css" href="med.css"  />
<style type="text/css">	
ponta {
	color:#FFFFFF;
	font-family:Arial, Helvetica, sans-serif;
	font-size:24px;
	font-weight:bold
}
pont {
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:18px;
	font-weight:bold;
}
waku {
	font-family:Verdana, Arial, Helvetica, sans-serif;
	font-size:14px;
	font-weight:800;
}
div#logo
{
	position:absolute;
	width:75px;
	left: 0px;
	top: 1px;
}
div#name
{
	position:absolute;
	width:400px;
	height:50px;
	left: 90px;
	top: 16px;
}
div#signin
{
	position:inherit;
	margin-top: 0px;
	width:500px;
	margin-right:auto;
	left:600px;
	height:75px;
	background-color:#00EA3A;
}
div#main
{
	position:relative;
	width: 1000px;
	height:700px;
	margin-top: auto;
	margin-left: auto;
	margin-right: auto;
	text-align:left;
	z-index:0;

}
div#parapantay {

	position:relative;
	width: 100%;
	margin-top: auto;
	margin-left: auto;
	margin-right: auto;
	z-index:1;
}
ponta {
	font-family:Arial, Helvetica, sans-serif;
	font-size:16px;
	font-weight:200;
	color:#000000;
}
A:link {text-decoration: none; color:#FFFFFF;}
A:visited {text-decoration: none; color:#FFFFFF;}
A:active {text-decoration: none; color:#FFFFFF;}
A:hover {text-decoration: underline; color:#00FFFF;}
	
body {
	text-align:center;
	margin:0;
}
</style>
</head>
<body>
  <div id="taas" style="background-color:#00EA3A; position:absolute; overflow:hidden; height:76px; width:100%; overflow:hidden; z-index:0; text-align:right; left: 1px; top: 0px;">&nbsp;</div>
<div id="parapantay">
<div id="logo" style="z-index:4; overflow:hidden;"><img src="images/logotouse.png" height="75px" width="75px" /></div>
<div id="name" style="z-index:3; overflow:hidden;"><img src="images/name.png" height="50px" width="400px"/></div>
<div id="signin" style="z-index:2; overflow:hidden;">
<br><br>
<a href="profile.php">Back to Profile</a> | <a href="logout.php">Logout</a>
</div>

<?php 

		$username = $_SESSION['username'];
	
		// this is for the paganation of records
		$per_page = 1;
		$pages_query = mysql_query("select * from tblpatient_info i, tbllab_bloodchem b, tbldoctor_info d, tblpatient_pass p where p.RelationMR_no = i.MR_no and i.MR_no = b.RelationMR_no and b.RelationDoc_ID = d.ID_no and p.username = '$username'");
		$pages = ceil(mysql_num_rows($pages_query) / $per_page);
		
		$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
		$start = ($page - 1) * $per_page;
			$query = "select * from tblpatient_info i, tbllab_bloodchem b, tbldoctor_info d, tblpatient_pass p where p.RelationMR_no = i.MR_no and i.MR_no = b.RelationMR_no and b.RelationDoc_ID = d.ID_no and p.username = '$username' LIMIT $start, $per_page";
		$result = mysql_query($query) or die(mysql_error());
		$record = mysql_num_rows($result);
		//iterates the records
		for($i=1;$i<=$result;$i++) {
		// check if their are records found
		if ($record!=0)
		{

			while ($row = mysql_fetch_row($result))
			{
				//print_r($result);
				$pName = $row[2]." ".$row[3]." ".$row[1];
				$dName = $row[47]." ".$row[48]." ".$row[46];
				$date = $row[14];
				$RBS = $row[15];
				$glucose = $row[16];
				$bun = $row[17];
				$creatinine = $row[18];
				$Bua = $row[19];
				$cholesterol = $row[20];
				$triglyceride = $row[21];
				$HDL = $row[22];
				$LDL = $row[23];
				$VLDL = $row[24];
				$OGT = $row[25];
				$GCT = $row[26];
				$calcium = $row[27];
				$others = $row[28];
				$totalpro = $row[29];
				$albumin = $row[30];
				$globulin = $row[31];
				$agratio = $row[32];
				$sodium = $row[33];
				$potassium = $row[34];
				$chloride = $row[35];
				$tbilirubin = $row[36];
				$dbilirubin = $row[37];
				$ibilirubin = $row[38];
				$sgot = $row[39];
				$sgpt = $row[40];
				$ap = $row[41];
				$mt = $row[42];
				$pathologist = $row[43];
				$time = $row[44];
?>
<script type="text/javascript">
<!--
function printDiv() 
{ 
  var divToPrint=document.getElementById('content'); 
  var newWin=window.open('','Print-Window','width=100,height=100'); 
  newWin.document.open(); 
  newWin.document.write('<html><body onload="window.print()">'+content.innerHTML+'</body></html>'); 
  newWin.document.close(); 
  setTimeout(function(){newWin.close();},10); 
 }
//-->
</script>

<div id="main">
<div id="blood" style="position:absolute; overflow:hidden; margin-left:auto; margin-right:auto; top:0px; width:805px; height:1002px; z-index:1; background-color:#FFFFFF; left: 90px;">
<div id="content" style="z-index:8; position:absolute; overflow:hidden; left:0px; top:0px; width:800px; height: 971px;">
<div id="headerpo" align="center">
<table cellpadding="2px" cellspacing="2px" border="0px">
<tr><td><img src="images/logotouse.png" height="75px" width="75px" /></td>
    <td><center><r style="font-weight:bolder; font-size:28px">Bernardino general Hospital</r><br>680 Quirino Hi-Way San Bartolome Novaliches Quezon City<br><r style="font-weight:bolder; font-size:20px">Blood Chemistry Laboratory Result</r></center></td>
</table>
</div>
	  <div id="record" style="z-index:9; position:absolute; overflow:hidden; left:10px; top:130px; width:700px; height: 850px;">
      <table cellpadding="2px" cellspacing="4px">
        <tr>
          <td width="400px"><b>Name: </b><?php echo $pName; ?></td>
          <td><b>Date and Time: </b></td><td><?php echo $date." ".$time; ?></td>
        </tr>
        <tr>
          <td colspan="3"><b>Doctor: </b><?php echo $dName; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Random Blood Sugar: </b><?php echo $RBS; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Glucose: </b><?php echo $glucose; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Bun: </b><?php echo $bun; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Creatinine: </b><?php echo $creatinine; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Bua: </b><?php echo $Bua; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Total Cholesterol: </b><?php echo $cholesterol; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Triglyceride: </b><?php echo $triglyceride; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>HDL: </b><?php echo $HDL; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>LDL: </b><?php echo $LDL; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>VLDL: </b><?php echo $VLDL; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Oral Glucose Tolerance: </b><?php echo $OGT; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Glucose Challenge Test: </b><?php echo $GCT; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Calciums: </b><?php echo $calcium; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Others: </b><?php echo $others; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Total Protein: </b><?php echo $totalpro; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Albumin: </b><?php echo $albumin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Globulin: </b><?php echo $globulin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>A/G Ratio: </b><?php echo $agratio; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Sodium: </b><?php echo $sodium; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Potassium: </b><?php echo $potassium; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Chloride: </b><?php echo $chloride; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Total Bilirubin: </b><?php echo $tbilirubin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Direct Bilirubin: </b><?php echo $dbilirubin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Indirect Bilirubin: </b><?php echo $ibilirubin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>SGOT: </b><?php echo $sgot; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>SGPT: </b><?php echo $sgpt; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>ALK PHOS: </b><?php echo $ap; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Medical Technician: </b><?php echo $mt; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Pathologist: </b><?php echo $pathologist; ?></td>
        </tr>
      </table>
	  </div>
  </div>



</div>
<div id="details"  style="border-left:hidden; text-align:center; border-right:hidden; overflow:hidden; height:75; width:100%; position:absolute; z-index:1; top: 1019px; left: 10px;">
<input name="button" type="button" onClick="printDiv()" value="Print Record" style="background-color:#00EA3A; font-size:16px; font-weight:300; color:#FFFFFF;" /><hr></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<?php

			}
		}
		
		else
		{
			die("No records to display");
		}
	}
?>
<div id="links"  style="border-left:hidden; text-align:center; border-right:hidden; overflow:hidden; height:75; width:100%; position:absolute; z-index:1; top: 1100px; left: 10px;">
<?php
if ($pages>=1 && $page<=$pages) {
	for ($x=1;$x<=$pages;$x++) {
	echo ($x == $page) ? '| <strong><a href="?page='.$x.'">'.$x.'</a></strong> |' : '| <a href="?page='.$x.'">'.$x.'</a> |';
	}
$array = $array+1;
}
?>
</div>
<?php
mysql_close();
?>
</body>
</html>
<?php
}
else
die("Please Login to view this page");
?>
?>
<script type="text/javascript">
<!--
function printDiv(id){ 
  var divToPrint=document.getElementById('content'+id); 
  var newWin=window.open('','Print-Window','width=100,height=100'); 
  newWin.document.open(); 
  newWin.document.write('<html><body onload="window.print()">'+content.innerHTML+'</body></html>'); 
  newWin.document.close(); 
  setTimeout(function(){newWin.close();},10); 
 }
//-->
</script>
<?php
if ($record!=0){
	$i = 0;
	while ($row = mysql_fetch_row($result)){
				//print_r($result);
				$pName = $row[2]." ".$row[3]." ".$row[1];
				$dName = $row[47]." ".$row[48]." ".$row[46];
				$date = $row[14];
				$RBS = $row[15];
				$glucose = $row[16];
				$bun = $row[17];
				$creatinine = $row[18];
				$Bua = $row[19];
				$cholesterol = $row[20];
				$triglyceride = $row[21];
				$HDL = $row[22];
				$LDL = $row[23];
				$VLDL = $row[24];
				$OGT = $row[25];
				$GCT = $row[26];
				$calcium = $row[27];
				$others = $row[28];
				$totalpro = $row[29];
				$albumin = $row[30];
				$globulin = $row[31];
				$agratio = $row[32];
				$sodium = $row[33];
				$potassium = $row[34];
				$chloride = $row[35];
				$tbilirubin = $row[36];
				$dbilirubin = $row[37];
				$ibilirubin = $row[38];
				$sgot = $row[39];
				$sgpt = $row[40];
				$ap = $row[41];
				$mt = $row[42];
				$pathologist = $row[43];
				$time = $row[44];
?> 
<div id="main">
<div id="blood" style="position:absolute; overflow:hidden; margin-left:auto; margin-right:auto; top:0px; width:805px; height:1002px; z-index:1; background-color:#FFFFFF; left: 90px;">
<div id="content" style="z-index:8; position:absolute; overflow:hidden; left:0px; top:0px; width:800px; height: 971px;">
<div id="headerpo" align="center">
<table cellpadding="2px" cellspacing="2px" border="0px">
<tr><td><img src="images/logotouse.png" height="75px" width="75px" /></td>
    <td><center><r style="font-weight:bolder; font-size:28px">Bernardino general Hospital</r><br>680 Quirino Hi-Way San Bartolome Novaliches Quezon City<br><r style="font-weight:bolder; font-size:20px">Blood Chemistry Laboratory Result</r></center></td>
</table>
</div>
	  <div id="record" style="z-index:9; position:absolute; overflow:hidden; left:10px; top:130px; width:700px; height: 850px;">
      <table cellpadding="2px" cellspacing="4px">
        <tr>
          <td width="400px"><b>Name: </b><?php echo $pName; ?></td>
          <td><b>Date and Time: </b></td><td><?php echo $date." ".$time; ?></td>
        </tr>
        <tr>
          <td colspan="3"><b>Doctor: </b><?php echo $dName; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Random Blood Sugar: </b><?php echo $RBS; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Glucose: </b><?php echo $glucose; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Bun: </b><?php echo $bun; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Creatinine: </b><?php echo $creatinine; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Bua: </b><?php echo $Bua; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Total Cholesterol: </b><?php echo $cholesterol; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Triglyceride: </b><?php echo $triglyceride; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>HDL: </b><?php echo $HDL; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>LDL: </b><?php echo $LDL; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>VLDL: </b><?php echo $VLDL; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Oral Glucose Tolerance: </b><?php echo $OGT; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Glucose Challenge Test: </b><?php echo $GCT; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Calciums: </b><?php echo $calcium; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Others: </b><?php echo $others; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Total Protein: </b><?php echo $totalpro; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Albumin: </b><?php echo $albumin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Globulin: </b><?php echo $globulin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>A/G Ratio: </b><?php echo $agratio; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Sodium: </b><?php echo $sodium; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Potassium: </b><?php echo $potassium; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Chloride: </b><?php echo $chloride; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Total Bilirubin: </b><?php echo $tbilirubin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Direct Bilirubin: </b><?php echo $dbilirubin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Indirect Bilirubin: </b><?php echo $ibilirubin; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>SGOT: </b><?php echo $sgot; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>SGPT: </b><?php echo $sgpt; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>ALK PHOS: </b><?php echo $ap; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Medical Technician: </b><?php echo $mt; ?> </td>
        </tr>
        <tr>
          <td colspan="3"><b>Pathologist: </b><?php echo $pathologist; ?></td>
        </tr>
      </table>
	  </div>
  </div>
 
 
 
</div>
<div id="details"  style="border-left:hidden; text-align:center; border-right:hidden; overflow:hidden; height:75; width:100%; position:absolute; z-index:1; top: 1019px; left: 10px;">
<input name="button" type="button" onClick="printDiv('<?php echo $i;?>')" value="Print Record" style="background-color:#00EA3A; font-size:16px; font-weight:300; color:#FFFFFF;" /><hr></div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<?php
 			$i++;
			}
		}

I've moved the script outside the while loop, so its just printed out once and added in an id variable to the function, it will now pick a div based on id eg. content0 or content5.

added a var $i = 0 before the while loop, whilst the while loop runs it will print it out into the printDiv function call eg. printDiv('0') or printDiv('5')
it then increases the number for every iteration of the loop making all the divs unique

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.