We help IT Professionals succeed at work.
Get Started

PHP echo help

pda4me asked
Last Modified: 2012-05-11
i have a <img tag that uses 2 column values from a database to define the source.  This is working great as it provides the unique id and the photo number - a value of 1 to show the last <img in the image tag.

There is a discrepancy however in the PhotoCount and the actual <img name when the PhotoCount value is less than 10.  

Here is the current code:

<img width="200" height="150" src="/images/<?php echo(rawurlencode($row['ListingID'])); ?>_<?php echo(rawurlencode($row['PhotoCount']-1)); ?>.jpg" alt="<?php echo(rawurlencode($row['ListingID'])); ?>" align="left" vspace="3" hspace="3" />

Open in new window

The problem arrives is when the PhotoCount is a 4 for example.  The <img tag would show up with a source of ListingID_4.jpg

The problem is that the actual file name is ListingID_04.jpg

I cannot change the database values to update the PhotoCount colum to a 04 so that the filename matches the PhotoCount returned ...how do I allow for this within PHP to insert a 0 if the value of PhotoCount is < 10?
Watch Question
Top Expert 2011
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE