HighDots Forums  

Need help with PHP and image

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Need help with PHP and image in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Deon H
 
Posts: n/a

Default Need help with PHP and image - 04-04-2009 , 02:33 PM






Hi guys and thanx so long for your help.

DW CS3, PHP & mySql.

I have a database with two fields for images; image_1 and image_2

It so happens that many of the records don't have an image_2 in the DB and
some have no images at all. How do I need to tweak the code so that no
error or place holder is shown. If there is an image, it must show the
image and if there is no image, no place holder or error message must show.
I don't want to have an image that says "No Image Available".

Thanx again for your help & time.
Deon



Reply With Quote
  #2  
Old   
Joe Makowiec
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 02:50 PM






On 04 Apr 2009 in macromedia.dreamweaver, Deon H wrote:

Quote:
Hi guys and thanx so long for your help.

DW CS3, PHP & mySql.

I have a database with two fields for images; image_1 and image_2

It so happens that many of the records don't have an image_2 in the
DB and some have no images at all. How do I need to tweak the code
so that no error or place holder is shown. If there is an image, it
must show the image and if there is no image, no place holder or
error message must show. I don't want to have an image that says "No
Image Available".
Hopefully you're just storing an image name, and not the image itself,
in the database?

<?php echo isset($row_myRecordset['image1']?"<img src='" . $row_myRecordset['image1'] . "alt='my image'>":''; ?>
<?php echo isset($row_myRecordset['image2']?"<img src='" . $row_myRecordset['image2'] . "alt='my other image'>":''; ?>

http://www.php.net/operators.comparison#language.operators.comparison .ternary

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php


Reply With Quote
  #3  
Old   
Joe Makowiec
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 02:54 PM



On 04 Apr 2009 in macromedia.dreamweaver, Joe Makowiec wrote:

Quote:
?php echo isset($row_myRecordset['image1']?"<img src='" . $row_myRecordset['image1'] . "alt='my image'>":''; ?
?php echo isset($row_myRecordset['image2']?"<img src='" . $row_myRecordset['image2'] . "alt='my other image'>":''; ?
Missed a parenthesis, two places, just before the question mark:

<?php echo isset($row_myRecordset['image1'])?"<img src='" . $row_myRecordset['image1'] . "alt='my image'>":''; ?>
<?php echo isset($row_myRecordset['image2'])?"<img src='" . $row_myRecordset['image2'] . "alt='my other image'>":''; ?>

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php


Reply With Quote
  #4  
Old   
Deon H
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 02:55 PM



Quote:
Hopefully you're just storing an image name, and not the image itself,
in the database?

?php echo isset($row_myRecordset['image1']?"<img src='" .
$row_myRecordset['image1'] . "alt='my image'>":''; ?> <?php echo
isset($row_myRecordset['image2']?"<img src='" .
$row_myRecordset['image2'] . "alt='my other image'>":''; ?

http://www.php.net/operators.comparison#language.operators.comparison .t
ernary

Hi Joe.

Yes, I am just storing the image name.

Regards,
Deon


Reply With Quote
  #5  
Old   
Deon H
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 03:25 PM



Quote:
Missed a parenthesis, two places, just before the question mark:

?php echo isset($row_myRecordset['image1'])?"<img src='" .
$row_myRecordset['image1'] . "alt='my image'>":''; ?> <?php echo
isset($row_myRecordset['image2'])?"<img src='" .
$row_myRecordset['image2'] . "alt='my other image'>":''; ?

Joe,

this is what I have:
<?php echo isset($row_rsResults['prod_image1'])?"<img src='" .
row_rsResults['prod_image1'] . "alt='my image'>":''; ?>

Now there is only a place holder and no image. I have double checked my
Recordset and the field name in the DB.

Anything else I can check?

Regards,
Deon


Reply With Quote
  #6  
Old   
Joe Makowiec
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 03:30 PM



On 04 Apr 2009 in macromedia.dreamweaver, Deon H wrote:

Quote:
this is what I have:
?php echo isset($row_rsResults['prod_image1'])?"<img src='" .
row_rsResults['prod_image1'] . "alt='my image'>":''; ?

Now there is only a place holder and no image. I have double checked
my Recordset and the field name in the DB.

Anything else I can check?
Change isset to !empty and see if that works:

echo !empty($row_rsResults['prod_image1'])?...

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php


Reply With Quote
  #7  
Old   
Mark A. Boyd
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 03:35 PM



Deon H posted in macromedia.dreamweaver

Quote:
Missed a parenthesis, two places, just before the question mark:

?php echo isset($row_myRecordset['image1'])?"<img src='" .
$row_myRecordset['image1'] . "alt='my image'>":''; ?> <?php echo
isset($row_myRecordset['image2'])?"<img src='" .
$row_myRecordset['image2'] . "alt='my other image'>":''; ?


Joe,

this is what I have:
?php echo isset($row_rsResults['prod_image1'])?"<img src='" .
row_rsResults['prod_image1'] . "alt='my image'>":''; ?

Now there is only a place holder and no image. I have double
checked my Recordset and the field name in the DB.
Your 2nd row_rsResults is not a variable (needs the $ in
front... $row_rsResults[].

Is the path to the image correct? As shown, that would be in the same
directory as the web page. If it is in an images directory, you would
need to prepend the path to the filename, using site root or doc
relative path.

<?php echo isset($row_rsResults['prod_image1']) ? '<img "src=/images/'
..$row_rsResults['prod_image1'] . '" alt="my image">' : ''; ?>

(Be careful. I may have messed up the single/double quotes in that
untested line.)


--
Mark A. Boyd
Keep-On-Learnin'


Reply With Quote
  #8  
Old   
Deon H
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 03:39 PM



Unfortunately not any luck. I'll browse around to see if I can find
something.
This is what I have now:
<img src="<?php echo $row_rsResults['prod_image1']; ?>" alt="Image"
height="100" align="right" />

Thanx for your time & help.

Deon



Joe Makowiec <makowiec (AT) invalid (DOT) invalid> wrote in
news:Xns9BE39DC8BB03makowiecatnycapdotrE (AT) 216 (DOT) 104.212.96:

Quote:
On 04 Apr 2009 in macromedia.dreamweaver, Deon H wrote:

this is what I have:
?php echo isset($row_rsResults['prod_image1'])?"<img src='" .
row_rsResults['prod_image1'] . "alt='my image'>":''; ?

Now there is only a place holder and no image. I have double checked
my Recordset and the field name in the DB.

Anything else I can check?

Change isset to !empty and see if that works:

echo !empty($row_rsResults['prod_image1'])?...



Reply With Quote
  #9  
Old   
Deon H
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 04:04 PM



Hi all.

with this:

<?php echo isset($row_rsResults['prod_image1']) ? '<img "src=' .
$row_rsResults['prod_image1'] . '" alt="my image">' : ''; ?>

The place holders show where there ARE images and nothing shows where there
are NO images. I will play around with the path as I am sure this is the
last hurdle to success.

Thanx,
Deon

Reply With Quote
  #10  
Old   
Mark A. Boyd
 
Posts: n/a

Default Re: Need help with PHP and image - 04-04-2009 , 04:10 PM



Deon H posted in macromedia.dreamweaver

Quote:
Hi all.

with this:

?php echo isset($row_rsResults['prod_image1']) ? '<img "src=' .
$row_rsResults['prod_image1'] . '" alt="my image">' : ''; ?
Oops. Looks like

'<img "src='
sb
'<img src="'



--
Mark A. Boyd
Keep-On-Learnin'


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.