How to display the image within a div tag..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gunasegar
    New Member
    • Aug 2010
    • 10

    How to display the image within a div tag..?

    this is my query.. where i need to display the result in a div... it shows the result in print $a perfectly.. but i needed the result to be within a div..?
    Pls help me
    Code:
    <?php
    header('Content-Type: image/jpg');
    
    define('MYSQL_USER', '****');
    define('MYSQL_DB', 'upload');
    define('MYSQL_HOST', 'localhost');
    define('MYSQL_SERVER', 'localhost');
    
    $con = mysql_connect(MYSQL_HOST,MYSQL_USER);
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db(MYSQL_DB, $con);
    
    	 $query = 'SELECT *  FROM `file` order by id desc limit 1';
     
            // Execute the query
          //  $result = $dbLink->query($query);
    		$result = mysql_query($query) or die(mysql_error());  
    	//$content='';
    		while($row = mysql_fetch_array( $result )) {
    			$a = $row['data'];[CODE][CODE][CODE]
    [/CODE][/CODE]
    }

    //echo '<div style="width:20 0px; height:200px;"> ';
    sleep(2);
    print $a;
    //echo '</div>';
    //echo '<p><a href="test_imag e.php">Back to Main page</a></p>';
    ?>
    <html>
    <head>
    </head>
    <body>
    <div></div>
    </body>
    </html>[/CODE]
    Last edited by Dormilich; Aug 23 '10, 09:01 AM. Reason: Please use [code] tags when posting code.
  • Thew
    New Member
    • Aug 2010
    • 69

    #2
    Just do this

    Code:
    <html>
    <head>
    </head>
    <body>
    <div>
    <?php echo $a; ?>
    </div>
    </body>
    </html>
    Thew

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      You can also put PHP variables into strings and then print the whole thing.
      [code=php]<?php
      $name = "Atli";
      $str = "Hello, my name is $name";

      echo $str; // Hello, my name is Atli
      ?>[/code]

      Comment

      • Gunasegar
        New Member
        • Aug 2010
        • 10

        #4
        Hi Thew.,

        I tried that but it doesnt print the image...
        what should i do now..
        Pls help me

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Gunasegar, the code suggested by both Thew and Atli is basic PHP. When you say it does not print the image, do you mean it prints nothing, or something but not the image?

          What does $a print normally?

          Comment

          • Gunasegar
            New Member
            • Aug 2010
            • 10

            #6
            i found the answer... thanks guys...
            save this as test_view.php
            <html>
            <head>
            <title>
            </title>
            </head>
            <body>
            <div>
            <img src="test_viewe r.php"/>
            </div>
            </body>
            </html>

            Comment

            Working...