table with code and image
Moderator: General Moderators
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
table with code and image
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
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
- 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
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
Because of that code:
Error -> headers alredy sent
Code: Select all
header("Content-type: image/jpeg");
echo mysql_result($resultados1_query, 0);
- 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
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
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
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
file show_image.php
Is that?
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>";
?>
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;
?>
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: table with code and image
I think i can find the answer ...
- 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
Let me know if you don't find it.mariolopes wrote:I think i can find the answer ...
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
Thank you AbraCadaver. I can't put it to work. Please look at my code.
THis code works, i.e shows the imagem :
This code doesn't work:
The file show_image.php
Any help, please?
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;
?>
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>";
?>
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;
?>
-
mariolopes
- Forum Contributor
- Posts: 102
- Joined: Sun May 22, 2005 7:08 am
Re: table with code and image
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);