Displaying images from a database continued
With a select (php, mysql) I display all items from a table "news" which are not older than three weeks. Some items have images, some have not. Now I have the following code in the head section:
if (isset($row_rsNews['newspicsmall1'])) {
$image_info = getimagesize($row_rsNews['newspicsmall1']);
}
$dims = isset($image_info) ? $image_info[3] : '';
In the body I have this:
<?php do { ?>
...
<?php if (!empty ($row_rsNews['newspicsmall1'])) { ?>
<?php
if (isset($row_rsNews['newspicsmall1']) && file_exists('pics/$img_name')) {
$image_info = getimagesize($row_rsNews['newspicsmall1']);
}
$dims = isset($image_info) ? $image_info[3] : '';
?>
<div class="picdivright">
<a href="pics/<?php echo $row_rsNews['newspicbig1']; ?>"><img <?php echo $dims; ?> src="<?php echo $row_rsNews['newspicsmall1']; ?>" alt="" /></a>
<?php if (!empty ($row_rsNews['newspictext1'])) { ?>
<p><?php echo htmlspecialchars($row_rsNews['newspictext1']); ?></p>
<?php } ?>
</div>
The problem is: if there is an image in landscape (portrait) format in item1, all the other images are forced into that format even if they are in a portrait (landscape) format.
If I put the statements for width and height into the following expression everything works:
<?php
if (isset($row_rsNews['newspicsmall1'])) {
$image_info = getimagesize($row_rsNews['newspicsmall1']);
}
$dims = isset($image_info) ? $image_info[3] : '';
if (isset($row_rsNews['newspicsmall1']) && file_exists('pics/$img_name')) {
$image_info = getimagesize($row_rsNews['newspicsmall1']);
}
$dims = isset($image_info) ? $image_info[3] : '';
?>
Why does this work, but the first one fails? And is the last one a correct statement (I fear it isn't)?
Sorry for the two questions, and I hope I got the problem across to you.
Leolux
