Jump to content


Photo

Totally baffled on displaying image from Mysql db


  • Please log in to reply
34 replies to this topic

#21 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 13 September 2006 - 04:31 PM

Just print out the value of that field like I said to see what is in it.  maybe the image name was entered wrong or didn't get entered at all.  If the image name does print out then create a full url from it and then enter it in the address field of your browser directly to make sure the image is on your web site and it is located where expected. It should be one of those problems otherwise one of the code suggestions given by the other posters should have worked.

#22 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 13 September 2006 - 05:36 PM

http://www.plateaupr...42-15602495.jpg is the direct link.

Also, I rewrote the 'getimage.php' so it would just display the entries in the 'File1' image field. There's only 3 entries in that field in that table. It displays the image names. Check it out:

http://www.plateaupr...om/getimage.php

Here's the code for it. Excuse the sloppiness as i've made several revisions to it:

<?php

include 'config.php';
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());

$sql = "SELECT File1 FROM  plateau_pros";
mysql_query($sql);
$Result = mysql_query($sql);

echo "<table>";
while ($a_row = mysql_fetch_array( $Result ))
{
  echo "<tr><td>" . $a_row['File1'] . "</td></tr>\n";
}
echo "</table>";

?>


#23 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 13 September 2006 - 05:53 PM

ok, then this should work:
<?php
    echo '<img src="http://www.plateauprofessionals.com/images/photo/' . $image . '" width="150" height="175">';
?>
-replace $image with your db row field name and insert into your original page
-guess it would only actually work for 3 people in the db however

I entered the link into my browser
http://www.plateaupr...m/images/photo/
-there's maybe 20 pix in that directory.  by the way, I shouldn't be able to do that, you should place an index.php file in that directory so I can't do that

#24 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 13 September 2006 - 08:59 PM

Not much hair left! This is getting really frustrating as i've tried SOOOOOOOO many angles on this.

Ok, here's the latest. First, here's the 'official' display page for the profiles and images utilizing some dummy people entered into the database. The first entry has an image file named in the 'imageName' field. The others don't. I'm using this tag to summon the pic:

<?php echo '<img src="http://www.plateaupr...m/images/photo/' . $image . '" width='150' height='175'>'; ?>

You can view the page here: http://www.plateaupr...com/display.php

For some reason it's displaying the ';? where the image should display. That's problem #1

Now, when I change the image tag to remove the <?php echo code and just have the following:

http://www.plateauprofessionals.com/images/photo/' .  $image . '


Then the red x box shows but no image. So, if you check the properties (right click/properties) it shows this URL to the image:

http://www.plateauprofessionals.com/images/photo/%20.%20%20.%20'


I've even created a second sql query just for the images:

$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?





#25 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 14 September 2006 - 06:19 AM

after this
<?php
$sql2=("SELECT imageName FROM members WHERE imageName='memberid'");
$result2 = mysql_query($sql2) or die(mysql_error());
?>

set image variable with

<?php
$image = mysql_result ($result2, 0, 'imageName');
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#26 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 06:21 AM

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

#27 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 14 September 2006 - 06:26 AM

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)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#28 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 06:32 AM

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 imageName 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.

#29 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 06:44 AM

Barand, after inserting that line I get this error message:

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


You can view the page here: http://www.plateaupr...com/display.php

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.

#30 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 07:10 AM

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...

#31 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 10:18 PM

Still getting this error message:

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


From this line:

$image = mysql_result($result2, 0, 'photo');

Please advise. Thanks!

#32 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 14 September 2006 - 10:44 PM

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
<?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'>";
?>
If you are getting that error message its because it couldn;t find a record with id you specified.

To check for that event,
<?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'>";
}
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#33 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 11:02 PM

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:

http://www.plateaupr...com/display.php

This:

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

is leading to this:

while ($row = mysql_fetch_assoc($result)) {
  extract($row);
  echo <<<HTML  blah blah blah

and in the HTML is the image 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>

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.



#34 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,025 posts

Posted 14 September 2006 - 11:21 PM

I did it with a single row because you said

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?


If images now working ok in loop, do you now need that call that's producing the single row?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#35 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 14 September 2006 - 11:34 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users