Link to home
Start Free TrialLog in
Avatar of team2005
team2005

asked on

Display pictures from database

Hi!

Have this page:

<?php
  error_reporting(E_ALL);
  ini_set("display_errors", 1);

  require_once('RAY_EE_config.php');
  require_once('Connect_databse.php');
  $table6 = 'ImageTable';

  $sql = "SELECT * FROM {$table6}";
  $resultraptmp = sqlsrv_query($conn,$sql);

?>

<table>
  

  <?php

  $sql = "SELECT * FROM {$table6}";
  $rettmp = sqlsrv_query($conn,$sql);

  if( $rettmp === false )
  {
       echo "Error in executing statement 7.\n";
       die( print_r( sqlsrv_errors(), true));
  }
  
  $antbilder=0;
  while($row3 = sqlsrv_fetch_array($rettmp)){

     $antbilder= $antbilder+1;         
  }
  
  ?> 

  <?php
  if($antbilder>0)
  {
     
  ?>
    
    <tr>
  <?php 
    $sql = "SELECT * FROM {$table6}";
    $rettmp2 = sqlsrv_query($conn,$sql); 
    $i=0;
    $bilde[ ]=array();
   while($row3 = sqlsrv_fetch_array($rettmp2)){
       
       $bilde1 = "data:image/jpg;base64,"; 
       $bilde2 = $row3['TransImage'];
       $bilde[$i] = $bilde1 . $bilde2; 
       $i=$i+1;
    ?>


  <?php } ?>
 

 <?php
   for($i=0;$i=$antbilder;$i++)
   { ?>

        <td valign="top" class="rapport_image1">
           <img src='<?php echo $bilde[$i] ?>' hight="190" align="left">
        </td>
   <?php  }?>


  <?php
    if($antbilder>0)
  {?></tr><?php }
}  ?> 
   
</table>    

Open in new window


Its only looping ?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Its only looping ?
Whether the answer is "yes" or "no" the design you have here is going to be troublesome for you.  The correct design is to have the image files in the server file system and the URLs of the image files in the data base (along with any other information you want to keep about the images - tags, colors, etc).

Then you can generate HTML <img> tags.

Note that the header() must come first and be complete before any browser output whatsoever, even including invisible whitespace.  The HTML <table> statement on line 14 makes it impossible to issue header().
Avatar of team2005
team2005

ASKER

Hi!

The customer dont want the images stored as files, and they want to stored
the pictures in a database.

Why cant i use my code ?
Hi!

Sorry, my mistace...

I just have made this testfile, and forget to put in Header...
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ray's Comments above are spot on.  I would recommend visiting his links as well.
Hi!

I just take out the code from a bigger file (about 800 lines of code)

But see that i missed out header++

Here is the modified file with header..

<?php
  error_reporting(E_ALL);
  ini_set("display_errors", 1);

  require_once('RAY_EE_config.php');
  require_once('Connect_databse.php');
  $table6 = 'ImageTable';

  $sql = "SELECT * FROM {$table6}";
  $resultraptmp = sqlsrv_query($conn,$sql);

?>

<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8" />
<title>Agrippa report system 2</title>
<link href="css/redmond/jquery-ui-1.8.13.custom.css" rel="stylesheet" />
<script src='js/jquery.min.js' type='text/javascript'></script>

</head>
<body>

<table>
  

  <?php

  $sql = "SELECT * FROM {$table6}";
  $rettmp = sqlsrv_query($conn,$sql);

  if( $rettmp === false )
  {
       echo "Error in executing statement 7.\n";
       die( print_r( sqlsrv_errors(), true));
  }
  
  $antbilder=0;
  while($row3 = sqlsrv_fetch_array($rettmp)){

     $antbilder= $antbilder+1;         
  }
  
  ?> 

  <?php
  if($antbilder>0)
  {
     
  ?>
    
    <tr>
  <?php 
    $sql = "SELECT * FROM {$table6}";
    $rettmp2 = sqlsrv_query($conn,$sql); 
    $i=0;
    $bilde[ ]=array();
   while($row3 = sqlsrv_fetch_array($rettmp2)){
       
       $bilde1 = "data:image/jpg;base64,"; 
       $bilde2 = $row3['TransImage'];
       $bilde[$i] = $bilde1 . $bilde2; 
       $i=$i+1;
    ?>


  <?php } ?>
 

 <?php
   for($i=0;$i=$antbilder;$i++)
   { ?>

        <td valign="top" class="rapport_image1">
           <img src='<?php echo $bilde[$i] ?>' hight="190" align="left">
        </td>
   <?php  }?>


  <?php
    if($antbilder>0)
  {?></tr><?php }
}  ?> 
   
</table>    

</body>
</html>

Open in new window


So please explane what is so wrong with this code.

Thanks

I have many 1000 hours of coding, but not an expert
thanks