Jump to content

Archived

This topic is now archived and is closed to further replies.

simcoweb

Totally baffled on displaying image from Mysql db

Recommended Posts

Ok, makes sense. Then how would I call the image? Seems everything I try turns to mush. Example, please?

Share this post


Link to post
Share on other sites
see reply #22 by mainewoods

And in your query, are you sure it's imageName = 'memberid' or do you have a member id column?

(Also memberid should be $memberid if you are storing it in a variable)

Share this post


Link to post
Share on other sites
Yes, there is a 'memberid' column/field in the database.

Also, I may be wrong with the 'imagename' field. That may be an actual name like 'My Dog Charlie' instead of the actual filename. There's another field called 'fileName' that contains the image name so that needs to be switched. Just a note, though, the same data is in both fields presently so it would call the image in either case.

Now, i'm not 100% sure if i'm understnading the 'WHERE' part. My understanding is that i'm 'connecting' or 'referring' the [b]imageName[/b] to the member's ID ( 'memberid' ) so that it knows which one to display for which member. I'll admit i've been wrong on 99.9999% of my assumptions so that's probably another one. So, bottom line is i'm not 100% sure how i'd write that part of the query.

Share this post


Link to post
Share on other sites
Barand, after inserting that line I get this error message:

[quote]Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 46 in /home2/wwwplat/public_html/display.php on line 16[/quote]

You can view the page here: [url=http://www.plateauprofessionals.com/display.php]http://www.plateauprofessionals.com/display.php[/url]

Also note that the characters '; show up to the right of where the image should be displayed. This should be the closing of the echo statement but for some reason it's displaying it as text.

Share this post


Link to post
Share on other sites
UPDATE: The images now are viewable and are coordinated with the proper profile! However, that error code is still present. So, I can either edit that line or if you have another suggestion...

Share this post


Link to post
Share on other sites
Still getting this error message:

[quote]Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 46 in /home2/wwwplat/public_html/display4.php on line 16[/quote]

From this line:

[code]$image = mysql_result($result2, 0, 'photo');[/code]

Please advise. Thanks!

Share this post


Link to post
Share on other sites
So if your table has these columns
[pre]
member_id  |  imageName      | fileName
-----------|-----------------|----------------- 
    1      | My dog Charlie  | charlie.jpg
    2      | My cat Felix    | felix.jpg[/pre]
   
and you want to display the image of the cat, you need to
[code]<?php
$memberid = 2;
$sql = "SELECT fileName FROM members WHERE member_id = '$memberid'";
$result = mysql_query($sql);
$image = mysql_result($result,0,'fileName');
echo "<img src='$image'>";
?>
[/code]
If you are getting that error message its because it couldn;t find a record with id you specified.

To check for that event,
[code]<?php
$memberid = 2;
$sql = "SELECT fileName FROM members WHERE member_id = '$memberid'";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
    $image = mysql_result($result,0,'fileName');
    echo "<img src='$image'>";
}
?>
[/code]

Share this post


Link to post
Share on other sites
Hi Barand:

In your first example that pertains to calling a single row. I'm actually calling all the rows in that table as an array and displaying them in a 'while' loop. The images show up fine. But that error shows at the top of the page. Take a peek:

[url=http://www.plateauprofessionals.com/display.php]http://www.plateauprofessionals.com/display.php[/url]

This:

[code]$sql2=("SELECT photo FROM plateau_pros WHERE photo='photo'");
$result2 = mysql_query($sql2) or die(mysql_error());
$image = mysql_result($result2, 0, 'photo');[/code]

is leading to this:

[code]while ($row = mysql_fetch_assoc($result)) {
  extract($row);
  echo <<<HTML  blah blah blah[/code]

and in the HTML is the image code:

[code]<td style='padding-left: 10px; padding-right: 10px; padding-top:5px; padding-bottom:5px' width='229' valign='top'><img src='images/photo/$photo'  width='175' height='225'></td>[/code]

In the mysql database there's no more 'imageName' field. Didn't need it so I deleted it. Also, the 'fileName' field I changed the title to 'photo'. Plus, edited all code to use that field name. Seems to work fine except for that error.

Share this post


Link to post
Share on other sites
I did it with a single row because you said
[quote]
I've even created a second sql query just for the images:

Code:

$sql2=("SELECT imageName FROM members WHERE imageName='memberid'");
$result2 = mysql_query($sql2) or die(mysql_error());


And set a variable as: $image = $sql['imageName'];

No matter what i've done/do I can't get this simple friggin image to show up. Help?[/quote]

If images now working ok in loop, do you now need that call that's producing the single row?

Share this post


Link to post
Share on other sites
Apparently not  ;D  I commented them out. Error go bye bye and images still show up. I guess I wasn't sure if the images were showing up because of that line since they started showing up at the same time I inserted it. However, I made about 4,000,324,234,212 changes to that page so keeping up with what worked got a little screwy about 2am. Thanks again for the help, Barand!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.