table with code and image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

table with code and image

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: table with code and image

Post by AbraCadaver »

Why can't you show the image?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: table with code and image

Post by mariolopes »

Because of that code:

Code: Select all

 
header("Content-type: image/jpeg");
 echo mysql_result($resultados1_query, 0);
 
Error -> headers alredy sent
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: table with code and image

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: table with code and image

Post 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?
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: table with code and image

Post by mariolopes »

I think i can find the answer ...
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: table with code and image

Post by AbraCadaver »

mariolopes wrote:I think i can find the answer ...
Let me know if you don't find it.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: table with code and image

Post 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?
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: table with code and image

Post 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);
 
Post Reply