Jump to content

Passing part of img name


kurt.santo
 Share

Recommended Posts

All product images are in the same folder and follow the same naming convention. They are called product-id.jpg, where id will be a number from 1 to 300. I tried to pass the id as a parameter from the sidebar (for example <a href="item.php?id=36">) into img src via

<img src="product-<?php echo $_GET['id']; ?>.jpg" width="100" height="68" class="thumb">

, which does not work. How would you achieve this otherwise?Kurt

Link to comment
Share on other sites

If you are sending the ID through the URL then you'll be able to access it in $_GET, there's not a lot that's complicated about that. So what you posted will work if that page receives the id value in the URL.
It is passed to the URL (states /item.php?id=36), but does not show. In IE there is a placeholder showing, in FF nothing (only thin vertical line). I put the image now in same folder to make things simpler
  <img src="Furniture-1a-<?php echo $_GET['id']; ?>.jpg" width="100" height="68" class="thumb">

. Even went so far to copy the image name from the image itself???Kurt

Link to comment
Share on other sites

Check the source of the page, make sure that it's including the ID onto the filename, and obviously make sure the image exists at that path. But if a script gets a variable passed to it through the URL, you access it through $_GET, there's just nothing complicated about that. If you look at the generated source of the page and see the id in the image name then it's working correctly, but if it's not pointing to the correct path of the image then it's not going to show up regardless of how the filename gets written there.

Link to comment
Share on other sites

Check the source of the page, make sure that it's including the ID onto the filename, and obviously make sure the image exists at that path. But if a script gets a variable passed to it through the URL, you access it through $_GET, there's just nothing complicated about that. If you look at the generated source of the page and see the id in the image name then it's working correctly, but if it's not pointing to the correct path of the image then it's not going to show up regardless of how the filename gets written there.
Checked all what you said. After clicking the relevant nav item ('<a href="item.php?id=36">Shanghai</a>'), the source code correctly shows '<img src="Furniture-1a-36.jpg" width="100" height="68" class="thumb">'. Both files are in same folder and picture file is called 'Furniture-1a-36.jpg' (this is actually copied from file itself) :) Kurt
Link to comment
Share on other sites

jpg=JPG=jpeg=JPEG ???
It works now!!! Also, I do not understant why it did not work before. I just opened the file without doing any changes to it in FF and it shows... This is really weird. It did not work for few days and then without changing the thing... Wroom! Does this make sense to anyone (I mean, I am pleased it works now, but still interested what the issue might have been...)?Kurt
Link to comment
Share on other sites

It doesn't make sense, computers aren't like that. If the environment stays the same, the computer does the same thing. The only reason the computer does anything different is if the environment changed.
What do you mean by environment? Does this refer to what other programs I had open at the time or similar?Kurt
Link to comment
Share on other sites

No, the variables that are involved in PHP running the script, and the browser getting the request. If the code is the same, the PHP configuration is the same, and all the files are the same, then the browser will do the same thing (assuming the internet connection stays on).

Link to comment
Share on other sites

No, the variables that are involved in PHP running the script, and the browser getting the request. If the code is the same, the PHP configuration is the same, and all the files are the same, then the browser will do the same thing (assuming the internet connection stays on).
That is so strange... But anyhow, I am pleased it is working now... Cheers!Kurt
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...