jseaman Posted July 24, 2007 Share Posted July 24, 2007 I'm having a hard time finding information (probably due to how I'm phrasing my searches) on how to assign a variable to an href. The big picture is I have a bunch of photos I'm trying to put on my website. I have an equally large bunch of thumbnails with links, all to the same page (pictures.php) that has a snippet of php (seen below). In my links I am attempting to assign a value to a variable that corresponds with a picture. Here is the php snippet in pictures.php: <?php echo '<img src=images/'. $picture. '.jpg>'; ?> Now, this is how my href looks on the page with all the thumbnails: <a href="index.php?page=pictures.php" name="picture" value="pic001">[thumbnail]</a> My php is fine, when I look at the source on the web it looks like <img src=images/.jpg>. So the problem obviously lies in how I'm doing my link. My questions are, can I do what I'm trying to do? If so, how? If not, what's another similar method I can do to make this work? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 24, 2007 Share Posted July 24, 2007 Try this: <?php echo "<img src='images/$picture.jpg'>"; ?> Quote Link to comment Share on other sites More sharing options...
envexlabs Posted July 24, 2007 Share Posted July 24, 2007 Hey, It doesn't look like you have any code grabbing the page=picture.php, which would be a $_GET , if echo'd would be picture.php You could set different variables and use an if: $test = $_GET if($test == "one") { $picture = "matt.jpg"; }else{} Then $picture would have a value of matt.jpg It just looks like your trying to pass a variable that isn't being defined. Quote Link to comment Share on other sites More sharing options...
jseaman Posted July 24, 2007 Author Share Posted July 24, 2007 You'll have to excuse me, I'm not very familiar with PHP, thus I'm finding this really confusing. I understand the if statement provided. What I don't understand the $_GET or how it is being used. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted July 24, 2007 Share Posted July 24, 2007 Rebuild your code like like so: <a href="index.php?page=pictures.php&picVal=pic001" name="picture">Link Text/Image</a> <?php //Rebuild your PHP like so: $picture = $_GET['picVal']; echo '<img src=images/'. $picture. '.jpg>'; ?> Quote Link to comment Share on other sites More sharing options...
jseaman Posted July 24, 2007 Author Share Posted July 24, 2007 Thanks, that works well. Not quite as I had hoped, but it works none-the-less. Thank you again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.