image database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
snoooop
Forum Newbie
Posts: 2
Joined: Thu Dec 22, 2005 10:03 pm

image database

Post by snoooop »

HawleyJR | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

I'm trying to design an image database like this:
[url]http://hitchcock.itc.virginia.edu/Slavery/return.php?categorynum=1[/url]

so far i wrote my php code as:

Code: Select all

<?php

// Make a MySQL Connection
mysql_connect("localhost", "myID", "myPSW") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());

$result = mysql_query("SELECT * FROM tbimg") 
or die(mysql_error()); 

echo "<table border='1'>";
echo "<tr> <th>id</th> <th>image</th> <th>description</th><th>price</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
header("Content-type: image/jpeg");
echo <img src=\"{$row['image']}\">
echo "</td><td>"; 
echo $row['description'];
echo "</td><td>"; 
echo $row['price'];
echo "</td></tr>";
} 
echo "</table>";

?>
why won't my images appear?

HawleyJR | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

first of all get rid of

Code: Select all

header("Content-type: image/jpeg");

are your images url's stored in the table? view the source of your page and see if img src="" has the same url as what you have in the database, also check if that url is valid
MaNiAC
Forum Newbie
Posts: 20
Joined: Fri Dec 23, 2005 4:20 am

Post by MaNiAC »

Code: Select all

<?php

// Make a MySQL Connection
mysql_connect("localhost", "myID", "myPSW") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());

$result = mysql_query("SELECT * FROM tbimg")
or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>id</th> <th>image</th> <th>description</th><th>price</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo "<img src=".$row['image'].">";
echo "</td><td>";
echo $row['description'];
echo "</td><td>";
echo $row['price'];
echo "</td></tr>";
}
echo "</table>";

?>
Haven't tested it...

echo <img src="{$row['image']}\">
there's no "; at the end :P
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

MaNiAC wrote:

Code: Select all

<?php

// Make a MySQL Connection
mysql_connect("localhost", "myID", "myPSW") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());

$result = mysql_query("SELECT * FROM tbimg")
or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>id</th> <th>image</th> <th>description</th><th>price</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo "<img src=".$row['image'].">";
echo "</td><td>";
echo $row['description'];
echo "</td><td>";
echo $row['price'];
echo "</td></tr>";
}
echo "</table>";

?>
Haven't tested it...

echo <img src="{$row['image']}">
there's no "; at the end :P
Are you referring to:

Code: Select all

echo "<img src=".$row['image'].">";
If so, there is a ; it is at the end of the sting :)
snoooop
Forum Newbie
Posts: 2
Joined: Thu Dec 22, 2005 10:03 pm

Post by snoooop »

thank you.
haha i went to phpfreaks.com and posted the same question and some guy said to add the header...

Anyways, I think I solved the problem.
before I only inserted the link address cause I thought I could write the php code to do what I wanted.
But then I typed <img src="http://hostname/image.jpg"> and then it worked.

The only thing that baffles me is that gif's don't appear. It's clearly a valid image data on my site, but it won't appear. Oh well, I can just change'em all to jpg.

here's the thing I made.
http://www.omarica.com/DWMX/select.php
Post Reply