Jump to content

Archived

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

simcoweb

Image Display Help.. please?

Recommended Posts

I'm at a complete standstill with finishing a project where I have to display an image of each person that's a member of a modest sized organization (about 25 people). I have the pictures uploading fine to the proper directory on the server. I even have the file name inserted into the Mysql database.

What I can't figure out is HOW to call the proper image for the right person. The image file name is in the same table row as the other information about the person (name, username, phone, etc.) Perhaps I should have a separate table for the images with an image_id field that is auto-incremented and connect the person to the image_id?

I'm looking for some help here on where to go from here. The page i'm putting this into is here:

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

This is driving me NUTS as i've spent literally 5 days researching and testing. Help?

Share this post


Link to post
Share on other sites
please don't name you're topics with something like HELP ME...
titles are meant to give people an idea of what's inside

If you would could you come up with a decent title..you will get more help that way to
and don't start a new topic....


and as for you're question...you'll have to use URL variables AKA GET vars
like
display?id=89

would pull up the profile info for profile id #89 with an SQL statement

Share this post


Link to post
Share on other sites
When you link to the individual persons page embed their emplyee_id.

so the page looks like this

www.url.com?employee_id=3.

Then, on the idividual persons page. Use something like

$employee = $_GET['employees_id'];

Yow have their employee id as an variable. Run a query in MySQl for

WHERE employee_id = $employee and you will have everything from that row for use in the table.

that's a basic overview....

Share this post


Link to post
Share on other sites
I changed the title. Sorry for being a little wild with that one.

Ok, I understand what you're saying. I need to generate some type of 'id' flag to call the images that correspond to the proper profile.

Question is... how? I've searched until my eyeballs have bugged out of my skull. Most of the info is about calling up pics into a gallery or displaying all the pics in a folder.

Basically here's what i've got:

user registers and registration form includes photo upload
user can log in to change their information if they wish
photo gets uploaded to /images/photo folder

My 'display.php' page pulls each person's profile into the page and displays it in some semi-fancy html output. I've gotten all the detail stuff to show. What I can't figure out is how to set up the image system so that they will show.

So.. some guidance/examples/tutorials/code snippets would be MUCH appreciated. Thanks!

Share this post


Link to post
Share on other sites
jwwceo, thanks for that suggestion. I have thought of that as well. That would involve having some type of 'listing' or 'summary' page where visitor sees a category, clicks on it, then that displays a short blurb about each person with a link to their profile which would then show everything. That would allow me to use your method which might be the better way to go.

I had no idea this was so complicated. I was assuming I could just use an echo statement that included the image path and a variable set to call the image. But that ain't workin.

Any further guidance you can provide?

Share this post


Link to post
Share on other sites
[quote]What I can't figure out is HOW to call the proper image for the right person. The image file name is in the same table row as the other information about the person (name, username, phone, etc.)[/quote]

So when you retrieve the row for a specific person you can retrieve the image file name, right?  And then you can use something simple like:

[code]echo "<img src='". $row['image_file_name']. "'>"; // if database contains full file name & path[/code]

or maybe it's:

[code]echo "img src='images/photo/". $row['image_file_name']. "'>";[/code]

Share this post


Link to post
Share on other sites
AndyB, i've tried about 97 variations of that type of call.

The database does NOT contain the file path. Only the file name (like '4202842.jpg' for example)

I've inserted your suggestion and get this error when doing so:

[code]
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home2/wwwplat/public_html/display.php on line 51[/code]

Line 51 is this:

[code]<td style='padding-left: 10px; padding-right: 10px; padding-top:5px; padding-bottom:5px' width='229' valign='top'><? echo "<img src='images/photo/". $row['imageFile']. "'>"; ?></td>[/code]

Share this post


Link to post
Share on other sites
There's no error on line 51.  The php interpreter has finally 'broken' on line 51 because an earlier line has a mismatched ', " or something.  Post lines 40-51 and we'll spot it.

Share this post


Link to post
Share on other sites
Here's line 40 and up to 51:

[quote]while ($row = mysql_fetch_assoc($result)) {
  extract($row);
  echo <<<HTML
<div align='center'>
<table border='0' cellpadding='0' style='border-collapse: collapse' width='530'>
<tr><td colspan='2' background='http://www.plateauprofessionals.com/images/top2.gif' width='530' height='35' style='padding: 10px'><h2>$name</h2>
</td>
</tr><tr>
<td height='15' colspan='2'>
</td>
</tr>
<tr>[/quote]

Share this post


Link to post
Share on other sites
Oh, it's in the middle of a HEREDOC statement ... and I doubt we can start an echo in the middle of a chunk of stuff that's being echo'd starting from the <<<HTML.  Try this for line 51:

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

Share this post


Link to post
Share on other sites
GLORY BE TO GOD! THE IMAGES SHOW!

Now...one more question. HOW can I make those resize to a set of global dimensions? I mean, aside from putting in some height/width parameters, i'd like to have these 'resized' to the proper dimensions so I can keep their clarity and manipulate the display of these images from page to page.

I have this function code I snagged but not sure how i'd adapt it to my needs. Here it is:

[code]$mysock = getimagesize("images/photo/image_name_here");
// image resize function
function imageResize($width, $height, $target) {

/*takes the larger size of the width and height and applies the formula accordingly...this is so this script will work 
dynamically with any size image
*/
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);

//returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the
return "width=\"$width\" height=\"$height\"";
}[/code]

I would assume I could rename that '$mysock' variable and set the parameters to insert into the image src. Not sure. Guessing. Ideas?

Share this post


Link to post
Share on other sites
The way I'd do this is to have something like a constant width in mind...like all images will have such a width

and do some proportional math to the image's size
like
[code]
$mysock = getimagesize("images/photo/image_name_here");

$setWidth = 200;
function imageResize($width, $height, $target) {
$newHeight = 0;
$newHeight = ($setWidth * $height) / $width;

return "width='{$setWidth}' height='{$newHeight}'";
}
[/code]

Share this post


Link to post
Share on other sites
Thanks, Zanus. The only problem with having 'a' global size is that I may want the uploaded image to be displayed in 2 or 3 different sizes depending on the page being viewed. That way I can have just one image uploaded but have it viewed as a thumbnail, medium sized or full sized image.

In that code snippet it makes a reference to 'a' particular image. I need something that would point to the $imageFile or field name of the image used/uploaded by each individual. Can that be done?

Share this post


Link to post
Share on other sites
Also, in the event that IF there's no pic uploaded for a person I want it to display a placeholder pic or text that says No Photo Available. A placeholder pic would be nicer. I'm not sure how to implement this but my simple-logic mind has something like this:

$image = mysql_result($result2, 'imageFile');
[code]if (!isset ($image)) {
echo "No Photo Available";
} [/code]

Can someone point me in the right direction on having a substitute image to display? Thanks!

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.