>I am trying to build a "product detail" page that pulls data from a MYSQL
>database using PHP. The data for the page includes product images, which I
>am trying to link to (i.e. from their location on the web server) instead of
>loading the images into the database. However, I cannot find any sample code
>that seems to work. Two questions:
There's tons of it out there...
Though, I admit *finding* the working sample can be tough :-)
>1. Is this possible (i.e. to store the HYPERLINK to the image in the
>database , and as the results are returned to the product detail screen, the
>image file will be displayed)? OR RATHER do I need to store the physical
>image file in the database location and query it that way?
Not only do you not need to store the image data in the db, it's a Bad Idea
(tm), as often discussed here.
>2. The code sample below contains several lines that show a field populated
>with text that I am returning....the line under the //Test comment is the
>field that I'm trying to pull an image back for:
>
>printf("REL_PLAN7: %s<br>\n", mysql_result($result,0,"REL_PLAN7"));
>printf("REL_PLAN8: %s<br>\n", mysql_result($result,0,"REL_PLAN8"));
>printf("REL_PLAN9: %s<br>\n", mysql_result($result,0,"REL_PLAN9"));
>
>//test
>printf(mysql_result($result,0,<a href="FRONT_REND">FRONT_REND</a>);
>
>NOTE: "FRONT_REND" is the name of the database field, and it contains a full
>web address, not relative.
Hmmmm.
Try to think of it this way.
PHP "just" spews out HTML.
I need to spew out the HTML for my web-browser to display an image.
That HTML looks like: <IMG SRC=blahblahblah.jpg>
Or, if you want a link to that image, you'd use:
<A HREF=blahblahblah.jpg>Front Rendering</A>
(or something like that)
So, your code should be something not unlike:
printf("<IMG SRC=%s>", mysql_result($result, 0, 'FRONT_REND'));
or perhaps you want:
printf("<A HREF='%s'>Front Rendering</A>", mysql_result($result, 0,
'FRONT_REND'));
That said, let me point out a few "Big Picture" issues.
printf is incredibly useful for spitting out highly-detailed formatted text,
but it's also a bit slower than echo.
So, really, echo is probably going to be a better work-horse for you in the
long run.
Secondly, calling mysql_result() over and over and over instead of
mysql_fetch_row() once... Well, that's a lot slower.
So, ideally, your code should look more like:
# Maybe in a while loop, maybe not...
list($plan7, $plan8, $plan9, $front_rend) = mysql_fetch_row($result);
echo "$plan7<BR>\n";
echo "$plan8<BR>\n";
echo "$plan9<BR>\n";
echo "<IMG SRC='$front_rend'><BR>\n";
echo "<A HREF='$font_rend'>Front Rendering</A><BR>\n";
You might even have THUMBNAIL path in your database, as well as a FULLSIZE
path for your images:
echo "<A HREF='$fullsize'><IMG SRC='$thumbnail'></A><BR>\n";
--
Like Music? http://l-i-e.com/artists.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php