Good Day, I want to display all images but it seems hard to me fetch it with different sizes if my table is per row. Please take a look on the image.
You can see that the all images are inside the single row. So I used array to display it and call its column name to separate the width and height of every individual. How can I fetch it in rows form.
For example:
row1 : where image_one is stored
row2 : where image_two is stored
row3 : where image_three is stored
row4 : where image_four is stored
so basically it has primary key on it.
and heres the css for it:
which was took here in stack by SEAN
img {
height: 200px; // set a standard height
padding-bottom: 5px; // add a space between the img rows
}
.image-one-frame, .image-four-frame {
width: 66%; // make one and four 2/3 the width
}
.image-two-frame, .image-three-frame {
width: 33%; // make two and three 1/3 the width
}
.image-one-frame, .image-three-frame {
float: left; // make one and three float left
}
.image-two-frame, .image-four-frame {
float: right; // make two and four float right
}
$viewquery= mysqli_query($connection,"SELECT * from sales");
while($row = mysqli_fetch_assoc($viewquery)) {
echo' <div class="div-frame-five">';
echo' <img src="images/'.$row["image_one"].'" alt="" class="image-
one-frame">';
echo' <img src="images/'.$row["image_two"].'" alt="" class="image-
two-frame">';
echo' <img src="images/'.$row["image_three"].'" alt="" class="image-
three-frame">';
echo' <img src="images/'.$row["image_four"].'" alt="" class="image-
four-frame">';
echo' </div>';
}
THIS IS TABLE IN THE DB
Image Table
Related
I am developing a voucher printing application that prints serial numbers and pins from a MySQL table and displays them in a page.
The php code displays two records per row..with being in a separate column i.e two columns displayed side by side
Due to the format of the page (two records per row)..i can not display each record in a seperate table. Rather all records are contained in a "general" table.
The voucher printing requires two rows to be displayed on each page.
I implemented a "page-break-after: always" style to each row not divisble by two, but page break is not showing. My code is shown below:
$aray=array();
while($row=mysqli_fetch_array($sql_res))
{
$aray[]=$row;
}
$nr_elm=count($aray);
$table='<table width=100%><tr>';
$nr_col=2;
if($nr_elm>0)
{
$p=1;//This is the row counter
for($i=0;$i<$nr_elm;$i++)
{
$table.='<td><div style="border: 2px dashed #000;" ><div id="image" style="float:left;">
'.$p.' <img src="crswb1.png" height=80 width=60 />
</div><div id="texts" style=" float: none;
margin-left:60px;">
<p> Amount:'.$aray[$i]['amount'].' </p><p> Pin:17263648409</p><p> Serial:5374748548
</div></div></td>';
$col_to_add=($i+1)%$nr_col;
if($col_to_add==0)
{
if($p % 2 == 0) {
$table.="<tr style='page-break-after:always'>";
}
$table.='</tr><tr>';
$p++;
}
}
}
$table.='</tr></table>';
$table=str_replace('<tr></tr>','',$table);
echo $table;
?>
I viewed the page source and the "page break" style is showing for the neccessary row, as seen below
<tr style='page-break-after:always'></tr><tr><td><div style="border: 2px dashed #000;" ><div id="image" style="float:left;">
3 <img src="crswb1.png" height=80 width=60 />
</div><div id="texts" style=" float: none;
How can i ensure that the page break is displayed so that i can print only two rows per page?..Thanks.
The format of the page does not prevent you to use one table for every two values. E.g. use the following HTML Code:
<table id="table1">
<tr>
<td>This is cell No. 1 in Table 1</td>
<td>This is cell No. 2 in Table 1</td>
</tr>
</table>
<table id="table1">
<tr>
<td>This is cell No. 1 in Table 2</td>
<td>This is cell No. 2 in Table 2</td>
</tr>
</table>
together with the following CSS Code:
#media print {
table {page-break-after: always;}
/* prevent blank page at end */
table:last-of-type {page-break-after: auto;}
}
/* If you want the fields on one line */
table, tr {
width: 100%;
/* If the fields still don't fit on one line
* make the font-size smaller */
font-size: 0.9em
}
it will print one table per page. Notice that even the last table will cause a page-break.
To see this work I prepared a codepen here. Open the codepen and try to print the page. You should see every table on it's own page.
I scan trough a folder for images by using php,
i put them in a div with the ID of images.
I want that div to scroll on the x-axis and hide everything that overflows on the y-axis.
So here's my code.
HTML and PHP:
<div id="images">
<?php
//Displaying images
$imgID = 0;
foreach($images as $image) {
echo "<img id='img".$imgID."' onClick='displayImg(".$imgID.");' src='".$image."' height='".$imgHeight."' width='".$imgWidth."' />";
$imgID++;
}
echo "<script>var maxImages = ".$imgID.";</script>";
?>
CSS:
#images {
overflow-y:hidden;
overflow-x:scroll;
height:<?php echo $imgHeight; ?>px;
border:solid 1px #c4c4c4;
align-content:flex-start;
}
#images img {
padding:5px;
cursor:pointer;
float:left;
}
I've experimented a bit, But nothing i've tried seems to work.
Your question is slightly out of context but how about something like:
http://jsfiddle.net/bassmanpaul/u9Xx6/
This goes on the assumption that you have the image widths available in php ($imgWidth) which can allow you to create a large inner container.
Failing that you may need to give us a JSFiddle to demonstrate your issue in greater detail...
My URL: illandeistudio
If you scroll halfway down you will see a list of categories (Accessories, dinning, lighting...)
They are currently vertical. How can I get these to display horizontally? Optimally they would be 4 per line. Below is the PHP code which places all the "categories" into a div "nelson"
Thanks! This has been hell!
.nelson {
float: left;
padding: 0 3px;
}
Then just style the padding from there. You can replace padding: 0 3px; with width: 80px; and adjust it from there if you want the columns to be even (might look better).
If you want it to be centered with 4 columns (you have 7 items so it would be 4 columns, 2 rows, and the last column would only have 1 row).... not sure why you would want it like that but its possible. You would create a around the code you wrote, create a width, and add the attribute:
style="margin: 0 auto; width: 916px;"
Then you would adjust the width of that to be the product of 7 * the width of .nelson
I'd recommend just adjusting padding though and leave the menu going horizontally. all the way across for all 7 items.
use like :
<?php if (count($this->document->shoppica_categories_arr) > 0) : ?>
<ul id="categories">
<?php $i = 0; ?>
<?php foreach ($this->document->shoppica_categories_arr as $category): ?>
<?php $i++ ?>
<li <?php if ($i % 4 == 0) : ?> class="ln"<?php endif ?>><?php echo $category->getName() ?></li>
<?php endforeach ?>
</ul>
<?php endif ?>
css file :
ul#categories li {
float: left;
}
ul#categories li.ln {
clear: left;
}
What Tallboy said. :) You may also need to set a width for the .nelson divs to get them floating correctly and lining up.
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/
I am using php/mysql, and have a database table with image url. I would like to know how can I put them on a php page with a 3 x 3 table, such that each td will show a different image based on the image url from the database?
I want to create something like this, where the alphabets are the images:
|a|b|c|
|d|e|f|
|g|h|i|
So far, I am only able to use do while to create something like this:
|a| | |
|b| | |
|c| | |
Thanks.
This would be the general approach:
$query = "SELECT url FROM images LIMIT 9";
$resource = mysql_query($query);
# Get the number of images
$count = mysql_num_rows($resource);
$i = 0;
$per_row = 3;
# Start outputting the table
echo '<table><tr>';
while($row = mysql_fetch_assoc($resource)) {
# The image cell
echo '<td><img src="'.$row['url'].'" /></td>';
# If three cells have been printed, and we're not at the last image
if(++$i % $per_row == 0 && $i > 0 && $i < $count) {
# Close the row
echo '</tr><tr>';
}
}
# If the last row isn't 'full', fill it with empty cells
for($x = 0; $x < $per_row - $i % $per_row; $x++) {
echo '<td></td>';
}
echo '</tr></table>';
That is, just loop the results normally but on every third item, echo a row change (</tr><tr>). Just make sure that you don't print extra row changes at the beginning or the end, hence the additional conditions.
The resulting table should be something like this (line breaks added):
<table>
<tr>
<td><img src="image.jpg1" /></td>
<td><img src="image.jpg2" /></td>
<td><img src="image.jpg3" /></td>
</tr>
<tr>
<td><img src="image.jpg4" /></td>
<td><img src="image.jpg5" /></td>
<td><img src="image.jpg6" /></td>
</tr>
<tr>
<td><img src="image.jpg7" /></td>
<td><img src="image.jpg8" /></td>
<td><img src="image.jpg9" /></td>
</tr>
</table>
Use a counter to keep track of how many images you've displayed already, and only emit </tr><tr> every 3 images. Hint: $count % 3
You don't really need to do this with tables (think about it, you're just trying to display something in a grid, you're not really trying to create a table of things).
With a little CSS you can do it like this (you can use the appropriate HTML5 elements if you use html5-shiv for MSIE):
<div class="figure">
<img src="mypic.jpg" alt="">
<div class="description">Description goes here</div>
</div>
and in CSS:
.figure {
float: left;
margin-right: 10px; /* for space between the columns */
padding: 5px;
border: 1px solid #000;
background-color: #fff;
color: #000;
}
.figure .description {
margin-top: 1em;
font-variant: italic;
}
If they are all the same size and you want to force them into a NxN grid, you can wrap them in a div (class="grid") do something like this (3x3 grid, 100px inner figure width (i.e. 90px image width)):
.grid {
padding-left: 10px; /* to mirror the right margin of the last .figure in the row */
width: 350px; /* 3*100px + 2*10px margin + 3*2*5px padding */
}
.figure img {
width: 90px;
}
This way you can simply output the images in sequence in a loop without having to worry about where to wrap the rows (the wrapping is handled by CSS; if you don't force the grid to have a maximum width, it will wrap at the right end of the browser window).