Jump to content


Photo

Image Display Help.. please?


  • Please log in to reply
14 replies to this topic

#1 simcoweb

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

Posted 14 September 2006 - 05:20 AM

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.plateaupr...com/display.php

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

#2 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 14 September 2006 - 05:33 AM

lol great profile page...i cant really help ya...more out of fear from alonzo than anything else..good luck dude

#3 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 14 September 2006 - 05:35 AM

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

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#4 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 14 September 2006 - 05:41 AM

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

#5 simcoweb

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

Posted 14 September 2006 - 05:45 AM

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!

#6 simcoweb

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

Posted 14 September 2006 - 05:53 AM

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?

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 September 2006 - 05:54 AM

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


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:

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

or maybe it's:

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

Legend has it that reading the manual never killed anyone.
My site

#8 simcoweb

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

Posted 14 September 2006 - 06:01 AM

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:

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

Line 51 is this:

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


#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 September 2006 - 06:26 AM

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.
Legend has it that reading the manual never killed anyone.
My site

#10 simcoweb

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

Posted 14 September 2006 - 06:37 AM

Here's line 40 and up to 51:

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.plateaupr...images/top2.gif' width='530' height='35' style='padding: 10px'><h2>$name</h2>
</td>
</tr><tr>
<td height='15' colspan='2'>
</td>
</tr>
<tr>



#11 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 September 2006 - 06:44 AM

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:

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

Legend has it that reading the manual never killed anyone.
My site

#12 simcoweb

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

Posted 14 September 2006 - 06:59 AM

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:

$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\"";
}

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

#13 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 14 September 2006 - 07:24 AM

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
$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}'";
}

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#14 simcoweb

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

Posted 14 September 2006 - 01:49 PM

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?

#15 simcoweb

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

Posted 14 September 2006 - 02:20 PM

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');
if (!isset ($image)) {
	echo "No Photo Available";
}

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users