Page 1 of 1

table with code and image

Posted: Wed Jan 27, 2010 9:13 am
by mariolopes
Hi
I need to show one table with the records and one record is a image. How can I do this? I cannot show the image. any help, please?
Thank you

Re: table with code and image

Posted: Wed Jan 27, 2010 9:15 am
by AbraCadaver
Why can't you show the image?

Re: table with code and image

Posted: Wed Jan 27, 2010 9:31 am
by mariolopes
Because of that code:

Code: Select all

 
header("Content-type: image/jpeg");
 echo mysql_result($resultados1_query, 0);
 
Error -> headers alredy sent

Re: table with code and image

Posted: Wed Jan 27, 2010 9:37 am
by AbraCadaver
It's very hard to tell what you're trying to do, but you can't show an image like that on an existing page (meaning with other content such as HTML). You need to use an img tag and set the src to a PHP file that queries the DB and outputs the header and image.

viewtopic.php?f=1&t=110171&p=582727#p582727

Re: table with code and image

Posted: Wed Jan 27, 2010 10:00 am
by mariolopes
Hum... I think i understood. Hi try it but it doesn't work. The field with the image is called Imagem. Please can you see my code:
File mostraimagem.php

Code: Select all

 
<?php 
        $link = mysql_connect("localhost", "curso", "123") or die("Could not connect: " . mysql_error());
        mysql_select_db("mariolopes") or die(mysql_error());      
        $resultados_query = mysql_query("SELECT * FROM negocios where Id=39 ");
// html table
echo"<table border='2'>";
echo"<tr>";
echo"<td>Id</td>";
echo"<td>Imagem</td>";
echo"</tr>";
//fill the table with data
while($row=mysql_fetch_array($resultados_query)){
 
echo "<td>";echo $row['Id'];echo"</td>";
echo "<td>";
    echo '<img src="show_image.php?id=' . $row->Id . '">';
echo "</td>";
 }
echo"</tr>";
echo"</table>";
?>
 
file show_image.php

Code: Select all

 
<?php
$result = mysql_query('SELECT Imagem FROM negocios WHERE Id = 39');
$row = mysql_fetch_object($result);
header('Content-type: image/' . $row->".jpg");
echo $row->Picture;
?>
 
Is that?

Re: table with code and image

Posted: Wed Jan 27, 2010 10:34 am
by mariolopes
I think i can find the answer ...

Re: table with code and image

Posted: Wed Jan 27, 2010 10:45 am
by AbraCadaver
mariolopes wrote:I think i can find the answer ...
Let me know if you don't find it.

Re: table with code and image

Posted: Thu Jan 28, 2010 3:01 am
by mariolopes
Thank you AbraCadaver. I can't put it to work. Please look at my code.
THis code works, i.e shows the imagem :

Code: Select all

 
<?php
$mysql_id = mysql_connect('localhost', "curso", "123");
mysql_select_db('mariolopes',$mysql_id);
$result = mysql_query('SELECT Imagem FROM negocios WHERE Id = 39');
$row = mysql_fetch_object($result);
header('Content-type: image/jpg');
echo $row->Imagem;
?>
 
This code doesn't work:

Code: Select all

 
<?php 
$link = mysql_connect("localhost", "curso", "123") or die("Could not connect: " . mysql_error());
mysql_select_db("mariolopes") or die(mysql_error());      
$resultados_query = mysql_query("SELECT * FROM negocios where Id=39 ");
// html table
echo"<table border='2'>";
echo"<tr>";
echo"<td>Id</td>";
echo"<td>Imagem</td>";
echo"</tr>";
//fill the table with data
while($row=mysql_fetch_array($resultados_query)){
echo "<td>";echo $row['Id'];echo"</td>";
echo "<td>";
    //echo '<img src="show_image.php?Id=' . $row->Id . '">';
    echo '<img src="show_image.php?Id=39">';
echo "</td>";
 }
echo"</tr>";
echo"</table>";
?>
 
The file show_image.php

Code: Select all

 
<?php
$result = mysql_query('SELECT Imagem FROM negocios WHERE Id =39');
$row = mysql_fetch_object($result);
header('Content-type: image/jpg');
echo $row->Imagem;
?>
 
Any help, please?

Re: table with code and image

Posted: Thu Jan 28, 2010 3:08 am
by mariolopes
I think I found it. In the show_image.php I have to connect to my database:

Code: Select all

 
$mysql_id = mysql_connect('localhost', "curso", "123");
mysql_select_db('mariolopes',$mysql_id);