Sort images based on order number using laravel - php

I have 5 images. I need to show the images based on the order.
Now I have the order in the array like
2,3,5,1,4
Now my images are in $new->image1,$new->image2,$new->image3,$new->image4,$new->image5
My result should be like if order is as like above,
order is like $new->image2,$new->image3,$new->image5,$new->image5,$new->image1,$new->image4
How can I achieve this
<table style="text-align:justify" align="center" border="1" cellspacing="0" >
{{$new->img_order}}
<?php
$order_array = explode(",", $new->img_order);
$img1 = $new->image2;
dd($new->image2);
?>
<tr>
<td height="600" rowspan="3"><img width="350" height="910px" src="{{asset('collage/'.$new->image1)}}" class="img-responsive" alt=""></td>
<td height="300" colspan="2"><img width="500" height="300px" src="{{asset('collage/'.$new->image2)}}" class="img-responsive" alt=""></td>
</tr>
<tr>
<td width="250" ><img width="250" height="350px" src="{{asset('collage/'.$new->image3)}}" class="img-responsive" alt=""></td>
<td width="250"><img width="250" height="350px" src="{{asset('collage/'.$new->image4)}}" class="img-responsive" alt=""></td>
</tr>
<tr>
<td colspan="2"><img width="500" height="250px" src="{{asset('collage/'.$new->image5)}}" class="img-responsive" alt=""></td>
</tr>
</table>

I just wonder why you not save the image path in array, but with many image1, image2, .....
Without sorting the image, you can echo the image by the order array with
$new->{'image' . $order[0]}
$new->{'image' . $order[1]}
$new->{'image' . $order[2]}
...

Related

Resize width and height of images

I have content stored in mysql, as following:
<table width="450" cellspacing="1" cellpadding="1" border="1">
<tbody>
<tr>
<td><img width="513" height="680" align="left" alt=" src="/userfiles/image/pic.jpg" /></td>
<td><img width="315" height="700" align="left" alt=" src="/userfiles/image/DSC_0389.JPG" /></td>
<td><img width="580" height="320" align="left" alt=" src="/userfiles/image/ktxh.jpg" /></td>
</tr>
</tbody>
</table>
When I load from db, PHP and display in html by PHP, there is no problem.
Now, I want all images, be displayed by fixed width and height as 200 X 200 AND TABLE BORDER = '0'
<table width="200" cellspacing="1" cellpadding="1" border="0">
<tbody>
<tr>
<td><img width="200" height="200" align="left" alt=" src="/userfiles/image/pic.jpg" /></td>
<td><img width="200" height="200" align="left" alt=" src="/userfiles/image/DSC_0389.JPG" /></td>
<td><img width="200" height="200" align="left" alt=" src="/userfiles/image/ktxh.jpg" /></td>
</tr>
</tbody>
</table>
How do I solve this problem?
Replace with this code and css
<style>
.cstm
{
width:200px;
height:200px
}
table
{
border:0
}
</style>
<table width="200" cellspacing="1" cellpadding="1" border="0">
<tbody>
<tr>
<td><img class="cstm" align="left" alt=" src="/userfiles/image/pic.jpg" /></td>
<td><img class="cstm" align="left" alt=" src="/userfiles/image/DSC_0389.JPG" /></td>
<td><img class="cstm" align="left" alt=" src="/userfiles/image/ktxh.jpg" /></td>
</tr>
</tbody>
</table>
As you mention the $content is dynamic, can you try adding the style to the table as such:
<style>
table td>img
{
width:200px;
height:200px
}
</style>

While Loop in FPDF only prints 1 result

i'm having a problem with FPDF, i want to create a While Loop that returns every result that my SQL query does when i use Phpmyadmin, the problem here is that it only returns one. If i use
$pdf->Cell(190,10,''.$pdf_info2['format'].'',1,1,0);
it does print the result i want, but i need to return them in the table as i show below.
Ps: This is my firts question so i appolagise if i wasn't that clear o my problem.
Thanks in advance
$html='<table border="0">
<tr>
<td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="150" height="40" bgcolor="#e6e6e6"> </td>
<td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
<td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html2 = '<tr>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
<td width="150" height="40" bgcolor="#e6e6e6">.$pdf_info['format'].</td>
</tr>';
}
$pdf->WriteHTML($html);
$pdf->WriteHTML($html2);
Use this code:
First you must need to define before loop: $html2 = ''; and concatenate with $html2 .= in while loop see below code for updated code:
$html2 ='';
$html ='<table border="0">
<tr>
<td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="150" height="40" bgcolor="#e6e6e6"> </td>
<td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
<td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html2 .='<tr>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
</tr>';
}
$pdf->WriteHTML($html);
$pdf->WriteHTML($html2);
**Option1.**first you need to merger data with previous data so use $html .= $html;
Option2 update $pdf_info
to
$pdf_info2
and no need to use 2 $pdf->WriteHTML();
so total code will be
$html='<table border="0">
<tr>
<td width="150" height="40" bgcolor="#e6e6e6">Tipo</td>
<td width="150" height="40" bgcolor="#e6e6e6">Formato</td>
<td width="150" height="40" bgcolor="#e6e6e6"> </td>
<td width="150" height="40" bgcolor="#e6e6e6">Pago</td>
<td width="150" height="40" bgcolor="#e6e6e6">Editar</td>
</tr>';
while($pdf_info2 = $smth->fetch(PDO::FETCH_ASSOC)) {
$html .= '<tr>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
<td width="150" height="40" bgcolor="#e6e6e6">'.$pdf_info2['format'].'</td>
</tr>';
}
$pdf->WriteHTML($html);

Getting out of page

I have made a navbar in photoshop and converted into code using the Save to web function in Photoshop, now the navbar is getting displayed OK, but when I add other stuff code then it just gets out of the page, its width increases.
My navbar.html
<html>
<head>
<title>Couture Collection</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (Untitled-3) -->
<table id="Table_01" width="1366" height="78" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="5">
<img src="images/navbar_01.png" width="1125" height="21" alt=""></td>
<td colspan="2">
<img src="images/navbar_02.png" width="241" height="21" alt=""></td>
</tr>
<tr>
<td>
<img src="images/navbar_03.png" width="180" height="56" alt=""></td>
<td>
<img src="images/navbar_04.png" width="217" height="56" alt=""></td>
<td>
<img src="images/navbar_05.png" width="272" height="56" alt=""></td>
<td>
<img src="images/navbar_06.png" width="207" height="56" alt=""></td>
<td colspan="2">
<img src="images/navbar_07.png" width="414" height="56" alt=""></td>
<td>
<img src="images/navbar_08.png" width="76" height="56" alt=""></td>
</tr>
<tr>
<td>
<img src="images/spacer.gif" width="180" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="217" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="272" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="207" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="249" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="165" height="1" alt=""></td>
<td>
<img src="images/spacer.gif" width="76" height="1" alt=""></td>
</tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>
1125+241 = 1366 and 180+217+272+207+414+76 = 1366
So if you add another td it will increase your nav and exceed 1366px. Best way should be to use real HTML + CSS to make your navbar instead of generating it with photoshop because it's using fixed width (which is not responsive at all)

TCPDF - HTML table align right inside writeHTMLCell does not work

I create a table with HTML to be inserted into TCPDF::writeHTMLCell with this format. The table only contains image.
$html_table ='<table align="right" border="1">
<tr>
<td width="10%" align="center">
<img src="http://localhost/img1.png" width="40" height="40" />
</td>
<td width="10%" align="center">
<img src="http://localhost/img2.png" width="40" height="40" />
</td>
</tr>
<tr>
<td width="10%" align="center">
<img src="http://localhost/img3.png" width="40" height="40" />
</td>
<td width="10%" align="center">
<img src="http://localhost/img4.png" width="40" height="40" />
</td>
</tr>
</table>';
Here's the TCPDF code to create HTMLCell
$pdf->writeHTMLCell(100, '', '', $pdf->getY(), $html_table, 1, 0, 0, false, 'R', false);
Even thought the HTML can show the table at the right side of page, TCPDF only shows this table at the left side inside the cell.
What is the right code to put the table in align right, put in the right side of the HTMLCell ?

how to add dynamic image to td background image?

in this code i want to add $image variable to td background but i dont know if add it between quotes without any problems..or delete quotes..and how to get it from youtube video..thanks for helping
<table width="130" height="97">
<tbody><tr>
<td valign="center" width="130" align="center" background="showvideo.php_files/2_003.jpg" height="97">
<a href="http://www.mysite.com/video/watch.php?VDCID=42608">
<img src="showvideo.php_files/play_arrow.gif" alt=" Theme Song " border="0">
</a>
</td>
</tr>
</tbody></table>
there you go:
<td valign="center" width="130" align="center" background="<?php echo $image; ?>" height="97"></td>

Categories