Link to home
Start Free TrialLog in
Avatar of harrisonjf
harrisonjfFlag for United States of America

asked on

Need PHP - MySQL Coding Assistance

I think I know conceptually what I want to do, but I lack the technical coding skills to get it right.  Any help/guidance will be sincerely appreciated.

I am working with a simple MySQL membership database - one record for each member.

 I also have a set member photos (mugshots) stored as jpg images in a folder on the server.

I would like to store a path to each member's photo in the MySQL database record for that member and then, use PHP code, to grab that photo and display it as part of the member's "Profile".

So...

What is the proper way to store an image path in a MySQL field?
What PHP code do I need to grab & display the member's photo record?

Unfortunately, my MySQL & PHP coding & syntax skills are petty lame, so any specific code examples would me much appreciated.

Thanks!
Avatar of Chris Sandrini
Chris Sandrini
Flag of Switzerland image

Hi

I would just save the image name in the db if the images are stored in the same folder. You could pull the image name with mysql

$result  = mysql_query("SELECT image FROM membership WHERE member = 'user' LIMIT 1");

if(mysql_num_rows($result) > 0)
{
    while($row = mysql_fetch_assoc($result))
    {
         echo "<img src='/path/to/images/".$row['image']."'>";
     }
}

Open in new window


I just typed it without checking...but you get the idea
Avatar of Beverley Portlock
Images are converted to binary and then save in a column of type BLOB. To show the image you get the binary code and convert it back.

I have linked to a fairly good tutorial that you should be able to use to get all the code you need. Some bits of it you can probably skip.

http://www.phpriot.com/articles/images-in-mysql
Avatar of harrisonjf

ASKER

Hi Folks,

Thank you so much for your responses to my inquiry -- however, I'd prefer not to store the images themselves in the MySQL database -- just some sore of link or reference to them and their location on the server.

Also, while I'm sure that the direct MySQL code could work -- I am modifying an existing PHP script that already displays each club member's profile data -- so I would prefer a more direct PHP code based solution to display an image, if possible.  

(I do realize that PHP can execute MySQL code, if done correctly.  It's the "done correctly" part that becomes the issue for me)

Thanks,

---Jared harrison
Then post some code how / where you want to integrate it.
It would help if you could also paste up a table structure for the member data. If it is an existing system then it probably has the image columns already defined.
Thank you for the additional suggestions.  I will try to be much more specific in my request.

As an example, a record in the MySQL table has the filename of the photo (jared_harrison.jpg) stored in a text field called "Photo".

The PHP code I am trying to modify to display the actual photo, instead of the filename of the photo, currently looks like this:

55 <tr>
56 <th class="WADADataTableHeader">Photo</th>
57 <td class="WADADataTableCell"><?php echo($row_WADAsitelok['Custom10']); ?></td>
58 </tr>
59 </table>

So I am trying to use the $row... data in the above table cell to display the actual photo (vs. the filename) with code similar to this:

<?php
echo '<img src="../members/photos/jared_harrison.jpg"/>';
?>

While this seems like it shouldn't be too difficult, I can't seem to get the code and/or syntax right.  I get parsing errors no matter how I construct the phrase -- probably, because I am only guessing at the code, as opposed to knowing how to properly construct the PHP statement.

---Jared Harrison
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Simple, direct... and it WORKS!

Thanks!
You're welcome. Thanks for the points.