I have tried numerous different page-break rules on a table element and I've exhausted myself.
Project location:
https://github.com/xremainnameless/lead_tracker
The table I'm trying to print is located on 'leads_queue_u.php' inside the '#lead_wrapper_u' div. I dynamically create the table using 'scripts/fill_all_leads_u.php' and I print the table using the custom print button on the document.
No matter which css rules I've applied, I can't seem to force the page breaking. I deleted all of my attempts, as to show cleaner code. Here is a snippet of the #print CSS:
#media print {
#page {size: landscape;}
body * {visibility: hidden;}
#lead_wrapper_u, #lead_wrapper_u * {visibility: visible;}
#lead_wrapper_u button {visibility: hidden;}
#lead_wrapper_u {
position: absolute;
left: 0;
Top: 0;
}
}
I always advice to not use the print button in the browsers (ctrl + p); because each browser has it's own preferences. You can depend on other frameworks to print the pages into different formats. e.g. fpdf framework.
But, if you insist to use the browsers button to print, you can replace all the tables, with divs; Since divs are always break in the end of the page, without distortion the layout.
for example, if you have this code:
<table>
<tr>
<td>Name</td>
</tr>
<tr>
<td>City</td>
</tr>
<tr>
<td>DOB</td>
</tr>
</table>
.
.
.
Then, you have to remove the table elemnts, and replace by a div, like this:
<div style = "border:black solid;">
<div style = "border:solid black;">Name</div>
<div style = "border:solid black;">City</div>
<div style = "border:solid black;">DOB</div>
</div>
.
.
.
This will make sure that each div will break to next page, without looking like it's been cut.
Related
I am populating a <DIV id='area'> element using a PHP script and I want to repopulate the same DIV element by calling a PHP function in JavaScript if the user wishes to filter the information:
$("#area").load("update-dashboard.php?id=7263");
It populates the DIV element with the correct information but the CSS styling I'm using to format the information (eg. class="highlight") doesn't get applied for some reason. So what I get reads correctly if I view the underlying HTML but the browser doesn't format it according to the stylesheet.
<style type="text/css">
.Highlight {
background-color: #dcfac9;
cursor: pointer;
}
td.highcell {
padding-top: 8px;
padding-bottom: 8px;
}
</style>
Here's what my table should contain within the DIV section:
<table style='border-collapse: collapse;' border=0 width='100%' id='link-table'>
<tr class='highlight'>
<td class='highcell'>
NK51 SNR55
</td>
<td class='highcell' width=36>
<img src='status_2.png' border=0 width=32 height=32><td class='highcell'>18-Dec-15</td>
<td class='highcell'>NK51 SNR55</td>
<td class='highcell'></td>
<td class='highcell'></td>
</tr>
ADDITIONAL INFO:
I also use this jQuery code to highlight the rows in the Table - maybe it doesn't work with HTML loaded after the page appears - if so can it be reinitialised?
$(function ()
{
$('#link-table td:first-child').hide();
$('#link-table tr').hover(function ()
{
$(this).toggleClass('highlight');
});
$('#link-table tr').click(function ()
{
location.href = $(this).find('td a').attr('href');
});
});
Try changing your css from .Highlight to .highlight. CSS selectors are case-insensitive but the HTML class attributes are not.
I'm new to PHP and trying to make the tables appear next to each other instead of appearing under the first one. I was trying to use "table style="float: left"" but that apparently doesn't work in PHP, anyone have an idea of how to do this?
Tried to fix it using your help, but nothing happens, maybe I'm misunderstanding something, I'm not very great at this.
<html>
<head>
<title>Produktsida</title>
<style type=”text/css”>
table {
display: inline-block
width: 500px;
}
</style>
</head>
<body>
<?php
require_once 'dbconfig.php';
$result = mysqli_query($con,"SELECT * FROM produkt JOIN bild ON bild.idBild = produkt.idProdukt JOIN ingrediens ON ingrediens.idIngrediens = produkt.idProdukt");
?>
<table border='1'>
<?php
while($row = mysqli_fetch_array($result))
{
$imgData = base64_encode($row['Bild']);
?>
<tr>
<td>
<img src="data:image/jpeg;base64,<?php echo $imgData ?>" /> </td>
</tr>
<tr>
<td>
<?php echo $row['Produkt_Namn'] ?>
</td>
</tr>
<?php } ?>
</table>
<?php
mysqli_close($con);
?>
</body>
PHP has very little to do with this. The browser (which does the rendering) only sees the output from PHP (and any static files you reference).
table style="float: left" should work fine, just watch your quotes. You can't use an unescaped " inside a PHP string literal that is delimited by " characters.
Either use ' or escape the quote character.
PHP isn't a client-side language, it's server-side. Any output that you make in PHP is rendered as HTML.
By default, I believe tables are block level items, meaning that they don't allow content next to them.
What you can do is wrap your tables in a DIV element.
CSS
div.table-holder1 { width:50%; float:left; }
div.table-holder2 { width:50%; float:right; }
PHP
print '<div class="table-holder1"><table>...</table></div>';
print '<div class="table-holder2"><table>...</table></div>';
Unless you gave your tables a class, I'd do this:
<table class="myTableClass">
....
</table>
.myTableClass{width:40%; float:left; margin-right:5%}
That oghtta fix it
Not directly related to the question
My first tip would be to reformat your code without echoing every line of code:
<?php
$result = mysqli_query($con,"SELECT * FROM produkt JOIN bild ON bild.idBild = produkt.idProdukt JOIN ingrediens ON ingrediens.idIngrediens = produkt.idProdukt");
?>
<table border='1'>
<?php
while($row = mysqli_fetch_array($result)) { /* Begin looping the rows */
$imgData = base64_encode($row['Bild']);
?>
<tr>
<td>
<img src="data:image/jpeg;base64,<?php echo $imgData ?>" />
</td>
</tr>
<tr>
<td>
<?php echo $row['Produkt_Namn'] ?>
</td>
</tr>
<?php } /* End looping the rows */ ?>
</table>
<?php
mysqli_close($con);
?>
The answer
You have to style your table with css. By default tables are a block level element which automatically put a line break after the element.
There are two main types of display properties of css:
//The default for the tables, divs etc. Most elements use display: block.
display: block
//The default for span, img and some others
display: inline
As you may know, a span element doesn't put a line break after the element, so you could've used it if it was not for one problem: They don't have any real dimensions, so you can't set a width or height to them for example.
To solve this modern browsers has implemented display: inline-block which combines the no line break of a span and the dimensions of a div. According to caniuse it has closely to 93% browser support, so it's almost ready to be used.
If you want to go with display: inline-block, you could use this css snippet:
table {
display: inline-block
width: 500px;
}
If you would like to read more about inline-block, refer to this question about float vs inline-block.
I have done some research to find a way to use a link to expand/collapse some content. I can't see any problems with my code, but the link does nothing.
HTML code ;
echo "<div>";
echo "[Results]";
echo "[Results]";
echo "<table class=\"results\">";
Followed by php to populate table, then close the table and div.
CSS
.results, .show {display:none}
.hide:focus + .show{display:inline}
.hide:focus {display:none}
.hide:focus ~ .results {display:block ;
width: 20em;
margin-left: auto ;
margin-right:auto}
I'm having problems with my slideToggle function in jquery when I use divs created in a loop.
When I press one of the buttons I want it to show the corresponding div instead of all the divs underneath all the buttons.
This is my css:
<style>
.toggle { display:none;}
p { width:400px; }
</style>
Here is my loop with button and div
<?php
include('sql.php');
$i = 0;
while ($i < count($rows)) {
echo "
<button class='trigger'>
<table width='100%'>
<tr>
<td width='20%'><img src='http://localhost/app-side/Icons/beer_icon.png' /></td>
<td width='80%'><h2>{$rows[$i]['titel']} </h2></td>
</tr>
</table>
</button><br>
<div class='toggle'>
<p>
{$rows[$i]['info']}
</p>
</div>";
$i++;
}
?>
And here is my slideToggle function
<script>
$('.trigger').click(function(){
$('.toggle').slideToggle('fast');
});
</script>
Thank you in advance.
The easiest solution would probably be to wrap your entire looping html in a further div, and then amending your jQuery like so:
$('.trigger').click(function() {
$(this).siblings('.toggle').slideToggle('fast');
});
Since the two elements are now grouped inside a common parent, one can find the other using the siblings-method. Naturally, you can go about this in hundreds of ways, but this one struck me as the quickest and easiest.
Here's a fiddle: http://jsfiddle.net/QukC8/
I am trying to display images vertically 5 per row using php and I have achieved it.
I am also using a div and this seems to be creating a problem.
Images are displayed horizontally, but there seems to be a huge space between each image.
Heres the php code:
<table width="500" border="0" cellpadding="2" cellspacing="3">
<tr>
<?php
// get the images for the new videos
$query = "SELECT * FROM videos";
$result = mysql_query($query);
$numimages = 0;
while ($row = mysql_fetch_assoc($result)) {
extract($row);
// extract youtube id
preg_match('/[\\?\\&]v=([^\\?\\&]+)/', $video_link,$matches);
// $matches[ 1 ] should contain the youtube id
?>
<td valign="top">
<div id="videogallery">
<a rel="#voverlay" href="http://www.youtube.com/v/<?php echo $matches[ 1 ];?>?autoplay=1&rel=0&enablejsapi=1&playerapiid=ytplayer" title="<?php echo $video_title;?>">
<img src="http://img.youtube.com/vi/<?php echo $matches[ 1 ];?>/default.jpg" alt="<?php echo $video_title;?>" class="border_black" />
</a>
</div>
</td>
<?php
$numimages++;
if ($numimages%3 == 0)
echo "</tr><tr>";
}
?>
</tr>
</table>
This is the css:
#videogallery {
width:500px;
zoom:1;
}
#videogallery span{
display:block;
}
#videogallery a{
display:-moz-inline-stack;
display:inline-block;
zoom:1;
*display:inline;
position:relative;
vertical-align:top;
margin:3px;
width:160px;
font:12px/18px "Lucida Grande","Lucida Sans Unicode",Arial,Verdana,sans-serif;
font-weight:normal;
color:#333333;
text-decoration:none;
text-align:center;
opacity:0.87;
}
#videogallery a img{
display:block;
border:none;
margin:0;
}
#videogallery a:hover{
opacity:1;
}
I have noticed a few things. First, ids must be unique in html, but they are not in your document. You create <div id="videogallery"> in a loop, so that id appears multiple times. You should change the id into a class (or remove the div completely).
Also #videogallery is set to have a width of 500 pixels, which is also the width of the containing table. If you plan to have 5 images next to each other, the width of a div (or an image) should not exceed 100 px. Reducing the width should already help you to reduce the gap between images.
It's generally not a good idea to use tables for layout, it should be possible to get the same effect without tables. That gives you more flexibility. (Determining the number of images per row should be a layout issue, not a code issue.)
90% of that code is completely redundant.
You don't need the tables (in fact, it's considered very poor practice to use them for layout like this these days), and you don't need the wrapper <div> elements around your images.
Your <a> tags are already styled with display:inline-block;, so actually they should already line up horizontally without any of that stuff. Just put them next to each other, without all the extra junk, and they'll line up quite happily for you. You can use margin and padding to put any extra spacing between them that you do require.
All you need beyond that is a single wrapper <div> around the whole lot to enforce a fixed width for the whole block, so that they wrap onto new lines at the right points.
Hope that helps.
there seems to be a huge space between
each gap.
Do you mean a 7 pixel gap?
<table width="500" border="0" cellpadding="2" cellspacing="3">
you may avoid <table> alltogether by using div and css float see this http://css.maxdesign.com.au/floatutorial/tutorial0407.htm
See http://jsfiddle.net/ZfyRb/