I'm trying to develop an interactive website using php and i want to display image(retrived from mysql database) and some text on the home pag. but the image retrived from my database fills the whole page. how can i display both text and image on the same page?

Recommended Answers

All 9 Replies

Post your code.

    $username = 'root';
    $password= '';
    $host = 'localhost';
    $id = $_GET['image_id'];
    $con = mysql_connect($host,$username,$password) or die ('connection error');
    $db = mysql_select_db('test');
    $query = "select * from photo_galary where id=" . $id; //the fields are order as id,photo
    $result = mysql_query($query) or die('query error');
    $row = mysql_fetch_row($result);
    $content = $row[1];
    header('Content-type: image/jpg');
    echo $content;
    echo 'Some text here';

Are you saving image path or image data in database?? It is working for me for image data.

i save it as image data and it displays the image but the image fills the whole page. I want to display both the image and the text.

i think you may need to set up a box to put the img in ,

echo '<td><img width="300" src="',$row['pic'],'"/></a></td>';

thats how i keep mine to 300 wide, the hight is var. however you could add hight="300" i think

It displays not an image but a long text.

Member Avatar

Fo the image:

echo "<td><img width=\"300\" src=\"{$row['pic']}\" /></td>";

If you're saving paths. If using data, as you state. Have:

<img src="image.php?id=7" width="300" />

Where the id=7 is the image id from the DB and image.php contains your code.

Thank you very much it works now.

Member Avatar

Sweet, are we solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.