Reputation: 117
I have been looking around online trying to find out how to put in image that is echoed out using PHP into a table sell but have the table cell a fixed size, I'm hoping that I can get the image to re size in proportion to fix within the table cell. Images are going to vary in size therefore I was hoping it would see the images max relative high or width and display accordingly so at the end there may be a little gap in either width or height but the image will be re-sized and displayed within the set table cell. Any pointers will be much appreciated.
Here is my current PHP code for my table as of yet there is no fixed sizes:
<?php
foreach($searchResult1 as $row){
?>
<tr>
<td><b>Seller: </b><?php echo $row['Owner'];?></td>
<td><b>Asking Price: </b><?php echo $row['AskingPrice'];?></td>
</tr>
<tr>
<td><img src="images/<?php echo $row['PropertyID'];?>.jpg"></td>
<td><b>Town or City: </b><?php echo $row['Town'];?></td>
<td><b>Post Code: </b><?php echo $row['PostCode'];?></td>
</tr>
<tr>
<td><b>Address: </b><?php echo $row['PropertyAddress'];?></td>
</tr>
<tr>
<td><b>Description: </b><?php echo $row['Description'];?></td>
</tr>
<tr>
<td><b>Property ID: </b><?php echo $row['PropertyID'];?></td>
<td><b>Email: </b><?php echo $row['ContactEmail'];?></td>
<td><b>Contact: </b><?php echo $row['ContactNumber'];?></td>
</tr>
<tr>
<td><input type="button" value="Save" onClick="savePropertyButton(<?php echo $row['PropertyID'] ?>);" >
</tr>
<?php
}
?>
</table>
Upvotes: 1
Views: 4362
Reputation: 117
This is taken from http://www.lamp-tips.com/programming/php/how-do-i-resize-all-of-the-images-in-a-table-in-a-php-script/
Which makes me query my initial question as it sounds like it is impossible to do what i want to do just using HTML and table validation. As anyone had any experience with this guys solution. Thanks
If you were going to use php in an efficient way to better display the data, you could have PHP generate the table data and resize the images to a thumbnail of 200px wide to output.
To do this, you would create an array of all of your image paths. Then loop over the array to build your table data, as you loop over it, check if a thumbnail exists on the server, if so, display it. If not, call a function to resize the image and generate thumbnail.
Upvotes: 0
Reputation: 7243
Use css and give the image a width of 100%.
Example:
table img {
width: 100%;
}
Upvotes: 1