I have a large dataset from MySQL that I am displaying using PHP. If the user tries to print it, it has some 50 pages of data.
The entire data is displayed using tables and simple PHP echo-s that display the data in the table fields.
What I need is - when a user tries to print it OR export to PDF in Safari (Mac), the table headers should appear on all pages. How can this be done?
Thanks
Edit: I have enclosed the table headers under but it doesnt work. It's a plain HTML page with no scripts that just displays data from database.
Code
echo "<table border='1'>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th colspan=13>Item Info</th>
<th colspan=4>Lot Info</th>
</tr>
<tr>
<th bgcolor='#C8E3FF'>S.No.</th>
<th bgcolor='#C8E3FF'>Party Name</th>
<th bgcolor='#C8E3FF'>Item No.</th>
<th bgcolor='#C8E3FF'>Date</th>
<th>Flower</th>
<th bgcolor='#C8E3FF'>Lot No.</th>
<th bgcolor='#C8E3FF'>Avg Wt.</th>
<th bgcolor='#C8E3FF'>Total Weight</th>
<th bgcolor='#C8E3FF'>Detail Page</th>
</tr></thead><tfoot></tfoot><tbody>";
echo "<tr>";
echo "<td bgcolor='#C8E3FF' rowspan=".$itemCounter.">".$sno."</td>";
echo "<td bgcolor='#C8E3FF' rowspan=".$itemCounter.">".$row['partyName']."</td>";
while($row2 = mysqli_fetch_array($itemquery))
{
$itemNo++;
echo "<td bgcolor='#C8E3FF'>".$itemNo."</td>";
echo "<td bgcolor='#C8E3FF'>".$row2['date']."</td>";
//$flower = $flower + $row2['flower'];
echo "<td>".$row2['flower']."</td>";
echo "<td bgcolor='#C8E3FF'>".$row2['lotno']."</td>";
echo "<td bgcolor='#C8E3FF'>".$row2['avgwt']."</td>";
if ($row2['totalWeight'] == 0)
{
echo "<td bgcolor='#C8E3FF'> </td>";
}
else{
$totalWt = $totalWt + $row2['totalWeight'];
echo "<td bgcolor='#C8E3FF'>".$row2['totalWeight']."</td>";
}
echo "<td bgcolor='#C8E3FF'>".$row2['detailPage']."</td>";
echo "</tr>";
}
echo "<td bgcolor='#C8E3FF'><b>Total</b></td>";
echo "<td><b>".$flower."</b></td>";
echo "<td bgcolor='#C8E3FF'></td>";
echo "<td bgcolor='#C8E3FF'></td>";
echo "<td bgcolor='#C8E3FF'><b>".$totalWt."</b></td>";
echo "<td bgcolor='#C8E3FF'></td>";
echo "</tr>";
echo "<tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>";
}
echo "</tbody></table>";
As far as I know, if you properly use the THEAD section in the table, that header will be repeated on each page.
http://www.w3.org/TR/html4/struct/tables.html#h-11.2.3
added from http://www.w3schools.com/tags/tag_thead.asp:
Definition and Usage
The tag is used to group header content in an HTML table.
The element is used in conjunction with the and elements to specify each part of a table (header, body, footer).
Browsers can use these elements to enable scrolling of the table body independently of the header and footer. Also, when printing a large table that spans multiple pages, these elements can enable the table header and footer to be printed at the top and bottom of each page.
The tag must be used in the following context: As a child of a element, after any , and elements, and before any , , and elements.
Related
I want to change td color using if statement but somehow my code is not affecting all rows
this is my code :
require_once("../model/materiel.class.php" . "");
$mt=new materiel();
$data=$mt->afficher_tous1();
echo '<table id="customers2" class="table datatable table-striped">';
echo "<thead>
<tr>
<th>Qte disponible</th>
<th>Alert</th>
</tr>
</thead>";
echo "<tbody>";
foreach($data as $t){
echo "<tr>";
if ($t['qte_disponible_m'] == 0){
echo "<td bgcolor='red'>".$t['qte_disponible_m']."</td>";
}else if ($t['qte_disponible_m'] > $t['alert_m']){
echo "<td bgcolor='green'>".$t['qte_disponible_m']."</td>";
}else if ($t['qte_disponible_m'] == $t['alert_m']){
echo "<td bgcolor='yellow'>".$t['qte_disponible_m']."</td>";
}
echo "<td>".$t['alert_m']."</td>";
echo "</tr>";
}
echo "</tbody>";
echo"</table>";
the problem i have see the screenshot below :
If statement is like jumping next row
Add a class with the CSS background-color property (with !important if needed) to the TD instead of bgcolor. The bgcolor gets overwritten by the table-striped class.
I could use some help here, because I cannot figure out how to echo a php row (a URL) as a link to an image.
This is the code I already have
echo"<table border=1>
<tr>
<th width=80px>Release</th>
<th width=250px>Title</th>
<th width=200px>Genre</th>
<th width=200px>Developer</th>
<th width=200px>Publisher</th>
<th width=100px>Links</th>
</tr>";
while($row=mysqli_fetch_assoc($result))
{
echo"
<tr>
<td>{$row['game_release']}</td>
<td>{$row['game_name']}</td>
<td>";
$query="SELECT * FROM genre WHERE genre_id=".$row['game_genrea'];
$genrearesult=mysqli_query($link,$query); $genrearow=mysqli_fetch_assoc($genrearesult);
echo $genrearow['genre_name'];
echo "</td>
<td>{$row['game_dev']}</td>
<td>{$row['game_pub']}</td>
<td>{$row['game_site']}</td>
</tr>";
}
echo"</table>";
The last tabel data ($row['game_site']} echoes the URL right now, but I would like to have an image appear(ie a browser icon) that links to to the echoed website and which is saved in my images folder. Is that possible? I tried different syntaxes, but nothing seems to work.
The data being executed is a url, you will have to use some html to make it the href of an anchor tag and then provide an image inside the anchor tag to get what you want.
<td><img src=\"IMAGE_URL_GOES_HERE\" /></td>
Something like this should work:
echo "<td><a href='".$row['game_site']."'> <img src='image.gif'/></a></td>";
note the "a" tag with href
EDIT: If I use $colName instead of $colname, I'd have no issues. Stupid, simple fix.
I have a query pulling 6 columns from multiple tables. The final column is necessary to be used in a dynamic URL I'm generating, but I don't want that column to display on my table. How can I hide it/make it not show up? Is there a way to call the data, but not use it in my table?
Query ex:
SELECT a, b, c, d, e, exTable.f as CID
FROM table exTable
JOIN <other tables>
WHERE stuff happens
Table (you can see that my header row will hide fine, but the content won't):
<table>
<thead>
<tr>
<th class="header"><strong>A</strong></th>
<th class="header"><strong>B</strong></th>
<th class="header"><strong>C</strong></th>
<th class="header"><strong>D</strong></th>
<th class="header"><strong>E</strong></th>
<th class="header" style="display:none"><strong>F</strong></th> <!-- THIS WORKS -->
</tr>
</thead>
<tbody>
<?
foreach($tableData as $row)
{
echo "<tr>";
foreach($tableColNames as $colName)
{
if ($colname=='CID') {
echo "<td style='display:none'>" . $row[$colName] . "</td>"; <!-- THIS DOES NOT -->
}
elseif ($colName=='e') {
echo "<td><a href='http://my.url.here/".$row[CID]."_Document.pdf' target='_blank'>" . $row[$colName] . " </a></td>";
}
else {
echo "<td>" . $row[$colName] . "</td>";
}
}
echo "</tr>";
}
?>
</tbody>
</table>
You have a typo: $colname should be $colName.
if ($colname=='CID') {
Stupid, simple solution: use $colName instead of $colname.
I have a script written to grab a row from my database based on current session user, which outputs the row correctly, however I want to insert a small image to be displayed alongside of the echo'd row, and cannot figure out the proper syntax.
if ($row['lifetime']!="")
echo "<div style ='font:12px Arial;color:#2F6054'> Lifetime Member: </div> ".$row['lifetime'];
else
echo '';
?>
basically I want the image to appear right before or after the .$row appears, either or.
You can try:
<?php
if ($row['lifetime'] !== "") {
echo "<div style ='font:12px Arial;color:#2F6054'> Lifetime Member: </div>";
echo $row['lifetime'];
echo "<img src='' alt='' style='width:100px'/>";
}
?>
Just put the HTML for the image into the string you're echoing:
echo "<div style ='font:12px Arial;color:#2F6054'><img src="fill in URL here"> Lifetime Member: </div> ".$row['lifetime'];
You can try as below example
HTML
<table>
<thead>
<tr>
<th>No.</th>
<th>Customer Name</th>
<th>Photo</th>
<th ></th>
</tr>
</thead>
<tbody>
<?php
$tst=0;
$result = mysql_query("select * from acc_cust");
while($row = mysql_fetch_array($result))
{
echo "<tr class='odd gradeX'>";
echo "<td width=5%'>" . $row['ent_no']. "</td>";
echo "<td>" . $row['cust_name']. "</td>";
echo "<td><img src='[path]" . $row['cust_img'] . "' /></td>";
}
?>
</tbody>
</table>
hi i am using jquery datatable plugin to load mysql data into it so far its goin good but when the records are more the data table gets relatively slow to load so now i am stuck here and have no idea of what has to be done so can anyone help me in this
here is my code
<?php
$result = mysql_query("SELECT * FROM `mdb` ORDER BY grno");
?>
$(document).ready(function(){
$('#datatables').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[2, "desc"]],
"bJQueryUI":true
});
})
<table id="datatables" class="display">
<thead>
<tr>
<th>Srno.</th>
<th>Brno.</th>
<th>Name</th>
<th>Address</th>
<th>City</th>
<th>Pin</th>
<th>Mobile</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>$row[grno]</td>";
echo "<td align='center'>$row[brno]</td>";
echo "<td align='center'>$row[name]</td>";
echo "<td align='center'>$row[address]</td>";
echo "<td align='center'>$row[city]</td>";
echo "<td align='center'>$row[pin]</td>";
echo "<td align='center'>$row[mobile]</td>";
echo "<td><img src='images/edit.png'> <img src='images/delete.png'></td>";
echo "</tr>";
}
?>
</tbody>
</table>
Please have a look at here.
If you want to have server-side processing click here.