Nick D
Nick D

Reputation: 59

How can I put a description under image?

I have made a database with blob images and descriptions. The description is connected to the blob data with the same ID. In this code, the description is displayed right next to its image.

Show Images Page

$query = "SELECT * FROM `photo`.`photo`";
$query_run = mysql_query($query);
while ($data = mysql_fetch_array($query_run)) {
echo '<'.'img src="id.php?id='.$data['id'].'">';
$short_description = substr($data['description'], 0, 10);
$long_description = $data['description'];
echo $long_description;


}

echo "<br><a href='Photosite.php'>Upload a Photo</a>";

Converting blobs to jpegs for display page

$id = abs($_GET['id']);
$query = mysql_query("SELECT * FROM `photo`.`photo` WHERE id='$id'");
$data = mysql_fetch_array($query) or die (mysql_error());
$image = $data['image'];
$description = $data['description'];


$jpgimage = imagecreatefromstring($image);




    $image_width = imagesx($jpgimage);
    $image_height = imagesy($jpgimage);

    $new_size = ($image_width + $image_height)/($image_width*($image_height/45));
    $new_width = $image_width * $new_size;
    $new_height = $image_height * $new_size;

    $new_image = imagecreatetruecolor($new_width, $new_height);


    imagecopyresized($new_image, $jpgimage, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
      $imagearray = imagejpeg($new_image, null);
      header('Content-type: image/jpeg');

       echo $imagearray;

My question is how can I get the description to go UNDER the image displayed? and not have image next to description next to image next to description and so forth...?

Big help thanks! And yes I know some of my functions are out-of-date, no need to remind me thanks!

Upvotes: 1

Views: 224

Answers (2)

Joshua Burns
Joshua Burns

Reputation: 8582

If you want images next to each other with descriptions below each image, then:

<?php
$max_width = '200px'; // Set this to whatever the image's width is.

$query = "SELECT * FROM `photo`.`photo`";
$query_run = mysql_query($query);
while ($data = mysql_fetch_array($query_run)) {
    // short_description doesn't look like it's being used... ??
    $short_description = substr($data['description'], 0, 10);
    $long_description = $data['description'];
    echo '<div style="float:left;width:'.$max_width.';">';
    echo '    <img src="id.php?id='.$data['id'].'" />';
    echo '    <br style="clear:both;" />';
    echo      $long_description;
    echo '</div>';
}
echo "<br style="clear:both;"><a href='Photosite.php'>Upload a Photo</a>";    

Otherwise if you want images underneath each other with descriptions beneath image, then:

<?php
$query = "SELECT * FROM `photo`.`photo`";
$query_run = mysql_query($query);
while ($data = mysql_fetch_array($query_run)) {
    // short_description doesn't look like it's being used... ??
    $short_description = substr($data['description'], 0, 10);
    $long_description = $data['description'];
    echo '<div>';
    echo '    <img src="id.php?id='.$data['id'].'">';
    echo '    <br style="clear:both;" />';
    echo      $long_description;
    echo '</div>';
}
echo "<br style="clear:both;"><a href='Photosite.php'>Upload a Photo</a>";    

Upvotes: 1

James Coyle
James Coyle

Reputation: 10428

Try a line break before the description. You could also consider a simple two row one column table.

Upvotes: 0

Related Questions