We help IT Professionals succeed at work.

Need PHP - MySQL Coding Assistance

harrisonjf
harrisonjf asked
on
401 Views
Last Modified: 2012-08-13
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!
Comment
Watch Question

Chris SandriniSenior System Engineer
Top Expert 2012

Commented:
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
CERTIFIED EXPERT

Commented:
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

Author

Commented:
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
Chris SandriniSenior System Engineer
Top Expert 2012

Commented:
Then post some code how / where you want to integrate it.
CERTIFIED EXPERT

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

Author

Commented:
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
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Simple, direct... and it WORKS!

Thanks!
CERTIFIED EXPERT

Commented:
You're welcome. Thanks for the points.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.