How to disable looping inside do while loop in php? - php

I used php to generate rows of html table. Here is my code:
<?php $cols=mysql_num_rows($grds); ?>
<tr>
<td></td>
<?php do{ ?>
<td rowspan="<?php echo $cols; ?>" align="center">Internal<br />Grades</td>
<td colspan="2"> <?php echo strtoupper($row_grds['grade_name']);?></td>
<td align="center"><?php echo strtoupper($row_grds['igrade']);?></td>
</tr>
<?php } while ($row_grds=mysql_fetch_assoc($grds));?>
The html source generated by the above code is:
<tr>
<td></td>
<td rowspan="2" align="center">Internal<br />Grades</td>
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<td rowspan="2" align="center">Internal<br />Grades</td>//I don't want this.
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
My expected output is:
<tr>
<td> </td>
<td rowspan="2"> Internal<br /> Grade</td>
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>

<?php $i=0; while ($row_grds=mysql_fetch_assoc($grds)){ ?>
<tr>
<td></td>
<?php if($i==0): ?>
<td rowspan="<?php echo $cols; ?>" align="center">Internal<br />Grades</td>
<?php endif; ?>
<td colspan="2"> <?php echo strtoupper($row_grds['grade_name']);?></td>
<td align="center"><?php echo strtoupper($row_grds['igrade']);?></td>
</tr>
<?php $i++; } ?>

Related

HTML CSS PHP, Table design

i have a problem to create table like this image in website, can anyone help me to solve that?. blue line in picture. i just don't know how to create table like this image. especially reference no, it has custom border line.
Here is table design
you can check my code here too MY CODE
this is my code
<html xmlns="http://www.w3.org/1999/ifxhtml">
<head profile="http://www.w3.org/2005/10/profile">
<title>Glisten - A free web template</title>
</head>
<body>
<table width="800" border="1" align="center">
<tbody>
<tr>
<td colspan="2" align="center" bgcolor=""><table width="800" border="1" align="center">
<tbody>
<tr>
<td width="125">Reference No</td>
<td colspan="4"> </td>
<td colspan="2" bgcolor="#8B8A8A" align="center"></td>
</tr>
<tr>
<td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td>
</tr>
<tr>
<td>Site ID</td>
<td colspan="3" align="center"></td>
<td width="185">BSC Name</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Site Name</td>
<td colspan="3" align="center"></td>
<td>New Site ID</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Sales Cluster</td>
<td colspan="3" align="center"></td>
<td>LAC</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Ne Type</td>
<td colspan="3" align="center"></td>
<td>Config</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Band</td>
<td colspan="3" align="center"></td>
<td>PO Number</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Cell ID</td>
<td width="80" align="center"></td>
<td width="82" align="center"></td>
<td width="80" align="center"></td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="7" > </td>
</tr>
<tr>
<td align="center">Integration Date</td>
<td align="center"></td>
<td align="center">On Air Date</td>
<td align="center"></td>
<td align="center">Acceptance Date</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
</tbody>
</table>
</body></html>
First identify the total columns to be created.
Then use attribute of table like "colspan" to span the columns.
Add following style to your table (I have added class table in your second table tag):
<style type="text/css">
.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th
{
padding: 8px;
line-height: 1.42857143;
vertical-align: top;
}
table {
border-collapse: collapse;
border-spacing: 0;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
}
</style>
<table width="800" align="center">
<tbody>
<tr>
<td colspan="2" align="center" bgcolor=""><table class="table" width="800" border="1" align="center">
<tbody>
<?php
while($data = mysql_fetch_array($query)){
if($data['dt_report']=='Yes'){
$check_dt_report='checked="checked"';
}
else{
$check_dt_report='';
}if($data['kpi_stats']=='Yes'){
$check_kpi_stats='checked="checked"';
}
else{
$check_kpi_stats='';
}
if($data['clear_alarm']=='Yes'){
$check_clear_alarm='checked="checked"';
}
else{
$check_clear_alarm='';
}
if($data['configuration']=='Yes'){
$check_configuration='checked="checked"';
}
else{
$check_configuration='';
}
if($data['neighbor']=='Yes'){
$check_neighbor='checked="checked"';
}
else{
$check_neighbor='';
}
?>
<tr>
<td width="125">Reference No</td>
<td colspan="4"> </td>
<td colspan="2" bgcolor="#8B8A8A" align="center"><?php echo $data['no_ref']; ?></td>
</tr>
<tr>
<td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td>
</tr>
<tr>
<td>Site ID</td>
<td colspan="3" align="center"><?php echo $data['site_id']; ?></td>
<td width="185">BSC Name</td>
<td colspan="2" align="center"><?php echo $data['bsc_name']; ?></td>
</tr>
<tr>
<td>Site Name</td>
<td colspan="3" align="center"><?php echo $data['site_name']; ?></td>
<td>New Site ID</td>
<td colspan="2" align="center"><?php echo $data['new_site_id']; ?></td>
</tr>
<tr>
<td>Sales Cluster</td>
<td colspan="3" align="center"><?php echo $data['sales_cluster']; ?></td>
<td>LAC</td>
<td colspan="2" align="center"><?php echo $data['lac']; ?></td>
</tr>
<tr>
<td>Ne Type</td>
<td colspan="3" align="center"><?php echo $data['ne_type']; ?></td>
<td>Config</td>
<td colspan="2" align="center"><?php echo $data['config']; ?></td>
</tr>
<tr>
<td>Band</td>
<td colspan="3" align="center"><?php echo $data['band']; ?></td>
<td>PO Number</td>
<td colspan="2" align="center"><?php echo $data['po_number']; ?></td>
</tr>
<tr>
<td>Cell ID</td>
<td width="80" align="center"><?php echo $data['cell_id1']; ?></td>
<td width="82" align="center"><?php echo $data['cell_id2']; ?></td>
<td width="80" align="center"><?php echo $data['cell_id3']; ?></td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="7" > </td>
</tr>
</tbody>
</table>

EXIF image in php

I have a page that image gets uploaded to but the image are not the right way.
I know I need to use EXIF but I am new to this and lost where to start on this as it is in a while loop
can any one help me
thx jason
here is my code
<section class ="box_1">
<form id="evaluations" method="post" action="comments_page_add.php" enctype="multipart/form-data">`enter code here`
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Parent Entered</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
</tr>
<?php
while($rows = mysqli_fetch_array($results2)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="child[]" type="checkbox" id="child[]" value="<?PHP echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['given_name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['surname']; ?></td>
</tr>
<?php
}
?>
</table>
</section>
<section class ="box_3">
<?php
while($rows2 = mysqli_fetch_array($results3)){
?>
<table width="100%" border="2" bgcolor="#CCCCCC">
<tr>
<tr><td colspan="4" align="center"><img src='<?php echo $rows2['Photo_parth']; ?>' width='60%' height='150em'></td></tr>
<td align="center" bgcolor="#FFFFFF"><input name="image[]" type="checkbox" id="image[]" value="<?PHP echo $rows2['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows2['id']; ?></td></tr>
<td bgcolor="#FFFFFF"><?php echo $rows2['date']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows2['time']; ?></td>
</tr>
</table>
<?php
}
?>
</table>
</section>

How to automatically generate rowspan using php

In this code everything is perfect except that I could not generate rowspan in the Internal Grade cell. this line <td rowspan="<?php echo $cols;?>"> hides the bottom border while I expect to span the rows every time the code generates rows. Thanks for your input and sorry for using mysql() function. I am newbie.
<?php $cols=mysql_num_rows($grds); ?>
<table>
<?php do{ ?>
<tr>
<td> </td>
//This hide the bottom border
<td rowspan="<?php echo $cols;?>">Internal<br />Grades</td>
<td colspan="2"> <?php echo strtoupper($row_grds['grade_name']); ?></td>
<td><?php echo strtoupper($row_grds['igrade']); ?></td>
<?php } while ($row_grds=mysql_fetch_assoc($grds)); ?>
</tr>
</table>
The output is like below:
output is here
The code generated by php is:
<table>
<tr>
<td> </td>
<td rowspan="1"> </td>// A
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td rowspan="2"> </td>//B
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
</table>
I want to merge A and B
Expected output is:
<table>
<tr>
<td> </td>
<td rowspan="2"> Internal<br /> Grade</td>
<td colspan="2"> RHYMES</td>
<td align="center">B</td>
</tr>
<tr>
<td> </td>
<td colspan="2"> CONVERSATION</td>
<td align="center">A</td>
</tr>
</table>
You can do something similar to this:
<table>
<?php $row_grds = mysql_fetch_assoc($grds); ?>
<tr>
<td> </td>
<td rowspan="<?=$cols;?>">Internal<br />Grades</td>
<td colspan="2"> <?=strtoupper($row_grds['grade_name']);?></td>
<td><?=strtoupper($row_grds['igrade']);?></td>
</tr>
<?php while ($row_grds=mysql_fetch_assoc($grds)): ?>
<tr>
<td> </td>
<td colspan="2"> <?=strtoupper($row_grds['grade_name']);?></td>
<td><?=strtoupper($row_grds['igrade']);?></td>
</tr>
<?php endwhile; ?>
Its not perfect but you are using mysql_fetch_assoc, which on its own is not perfect either :D

store part of the page in variable

i have a page contains a table and this table contains a lot of coding like this
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
<? $res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){ ?>
<tr style="width:700px">
<td class="tabletext"><?= ++$serial;?></td>
<td class="tabletext" ><?= $resArr[stName];?></td>
<td class="tabletext"><?= $resArr['date'];?></td>
<td class="tabletext" ><?= $resArr[matName];?></td>
<td class="tabletext" ><? if($resArr[exam]==1) echo "work";else echo "final";?></td>
<td class="tabletext" ><? if($resArr[exam_type]==1) echo "prac";else echo "test";?></td>
</tr>
<? }?>
</tbody>
</table>
as you see the table has php coding
now i want to store the whole table in variable so i can send it to pdf printing library tcpdf
You can use heredoc syntax, but you need to move the conditionals outside:
<?php
if($resArr['exam']==1) $exam = "work"; else $exam = "final";
if($resArr["exam_type"]==1) $examtype = "prac";else $examtype = "test";
$var = <<<EOT
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
$res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){
<tr style="width:700px">
<td class="tabletext">{++$serial}</td>
<td class="tabletext" >{$resArr["stName"]}</td>
<td class="tabletext">{$resArr["date"]}</td>
<td class="tabletext" >{$resArr["matName"]}</td>
<td class="tabletext" >{$exam}</td>
<td class="tabletext" >{$examtype}</td>
</tr>
<? }?>
</tbody>
</table>
EOT;
echo $var;
Another way, if you already have all of this code and want to save it:
Before the table:
<?php ob_start(); ?>
After the table:
<?php $output = ob_get_contents(); ?>
The table will still be displayed and you can use $output to send to the PDF.

Print page setup in PHP

Am currently developing a web application which does the process of invoice etc.
Customer is using dot matrix printer to print invoice sheet. They said the requirement in printing as if there is more than 5 items in a sheet the rest should come as next sheet.
I have made that using PHP but i don't know how to print the next sheet in next page. It just prints as usual in sequence which results in a sheet printed in 2 pages. Any help or ideas will be appreciated. Below is the code how i generated sheet.
Thanks
<script type="text/javascript">
function printPage(){
var divElements = document.getElementById('printDataHolder').innerHTML;
var oldPage = document.body.innerHTML;
document.body.innerHTML="<link rel='stylesheet' href='css/common.css' type='text/css' /><body class='bodytext'>"+divElements+"</body>";
window.print();
document.body.innerHTML = oldPage;
}
</script>
<?php
$limit=5;
$cnt=0; // for table header and footer
$cnt2=1;// for no of rows count to print total values in end
$total=0;
?>
<div id="contentHolder" align="center">
<input type="button" value="Print" class="btnclass" onclick="printPage()" /> <input type="button" class="btnclass" value="Click to Proceed" style="width:100px;" onclick="Javascript:window.location.href='invoice.php';" />
<br />
<div id="printDataHolder">
<?php while($data=mysql_fetch_array($invcontents)){ ?>
<?php if($cnt==0){ ?>
<table width="800" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #4E9A91;">
<tr>
<td height="29" colspan="4" style="font-size:22px; padding-left:10px;"><strong>OvalTechnologies</strong></td>
</tr>
<tr>
<td colspan="4" style="padding-left:10px;"><?php echo($branchdetails['address']); ?></td>
</tr>
<tr>
<td height="19" colspan="4" style="padding-left:10px;">Website : www.ovaltechnologies.in Phone No : <?php echo($branchdetails['phoneno']); ?></td>
</tr>
<tr>
<td height="12" colspan="4" style="border-bottom:1px solid #4E9A91;"> </td>
</tr>
<tr>
<td height="28" colspan="3" style="padding-left:10px;">Customer Name : <?php echo($invtotal['customername']); ?></td>
<td width="226"> </td>
</tr>
<tr>
<td width="309" height="28" style="padding-left:10px;border-bottom:1px solid #4E9A91;">Invoice No : <?php echo($invoiceid); ?></td>
<td colspan="2" style="border-bottom:1px solid #4E9A91;">Paid As : <?php echo($invtotal['paidas']); ?></td>
<td style="border-bottom:1px solid #4E9A91;">Date : <?php echo(getonlydatefromdatetime(changefromdbdate($invtotal['invoicedate']))); ?></td>
</tr>
<tr>
<td height="28" class="rowborder" style="padding-left:10px;"><strong>Item Name</strong></td>
<td width="136" class="rowborder"><strong>Rate</strong></td>
<td width="129" class="rowborder"><strong>Qty</strong></td>
<td class="rowborder"><strong>Amount</strong></td>
</tr>
<?php } ?>
<tr>
<td align="center" height="28" style="padding-left:10px;"><?php echo($data['item']); ?> : <?php echo($data['brand']." "); ?><?php echo($data['type']); ?></td>
<td align="center"><?php echo($data['billedamount']); ?></td>
<td align="center"><?php echo($data['quantity']); ?></td>
<td align="center"><?php echo($data['billedamount']*$data['quantity']); ?></td>
</tr>
<?php
if($cnt2==$invcount){//printing emptylines to fill up page
for($i=$cnt+1;$i<$limit;$i++){
?>
<tr>
<td height="28" style="padding-left:10px;"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php
}
}//printing emptylines to fill page ends
?>
<?php if($cnt==$limit-1 || $cnt2==$invcount){ ?>
<?php if($invtotal['transport']!="") {?>
<tr>
<td style="padding-left:10px; border-top:1px solid #4E9A91;" class="rowborder" height="28">Transport : <?php echo($invtotal['transport']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Transport Cost : <?php echo($invtotal['transportcost']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Destination : <?php echo($invtotal['destination']); ?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"> </td>
</tr>
<?php } ?>
<tr>
<td height="28" class="rowborder" style="border-top:1px solid #4E9A91;"> </td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"><?php if($invtotal['transport']!="") {if($invtotal['addtransport']=="no"){echo("Transport Cost Not Added");}}?></td>
<td class="rowborder" style="border-top:1px solid #4E9A91;">Total</td>
<td class="rowborder" style="border-top:1px solid #4E9A91;"><?php echo($invtotal['totalamount']);?></td>
</tr>
<tr>
<td height="28"> </td>
<td> </td>
<td> </td>
<td align="center">Invoice Done By</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table><br />
<?php } ?>
<?php
$cnt++;
$cnt2++;
if($cnt==$limit){
$cnt=0;
}
} ?>
</div>
</div>
<?php
} ?>
do not see such options in http://www.php.net/manual/en/function.printer-set-option.php
but you can have look around the functions here http://www.php.net/manual/en/ref.printer.php
printer_start_doc — Start a new document
printer_start_page — Start a new page

Categories