Marsha Posted September 14, 2009 Share Posted September 14, 2009 Heya Here is my Code if (!empty($modSettings['down_set_t_title'])) echo '<td><a href="' . $scripturl . '?action=downloads;sa=view;down=', $file['ID_FILE'], '">', $file['title'], '</a></td>'; Basicly, That sets the Title of a file on my website, and the Title of the file is at $file['title'], I Need it to make that an Image, The image is called the same as the Title so thats not a problem, It's extension is .png and its location is /images/ So Effectively I need it to be /images/$file['title'].png How could I do this so it displays as an image? Sorry If I haven't explained this very well lol Thanks for any help! Marshall Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/ Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Try.. echo '<td><a href="' . $scripturl . '?action=downloads;sa=view;down=' . $file['ID_FILE'] . '"><img src="/images/' . $file['title'] . '" alt="' . $file['title'] . '" /></a></td>'; Also removed the mix of variable joins / concatenation. Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918177 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 So I would add this after my code? Or instead? Or aswell as the If statement? Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918183 Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Within the code you provided, replace the second line (the echo statement) with the line I posted. Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918187 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 Awesome! Thank you, One thing, How would I include the .png extension to the end? Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918188 Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Oh sorry yeah... echo '<td><a href="' . $scripturl . '?action=downloads;sa=view;down=' . $file['ID_FILE'] . '"><img src="/images/' . $file['title'] . '.png" alt="' . $file['title'] . '" /></a></td>'; Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918191 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 Thats the one Thanks very much for you help and fast response! Excellent Marshall Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918194 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 Sorry for this lol, But is there any way that I can have the title aswell as the picture? But so that when there is no picture, Only either the Alt of the picture, or the title is shown? To prevent the title being shown twice... Sorry if it's alot to ask Thanks Marshall Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918222 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 Just realised what I posted hahahah! Oh god that was dumb I only need the Title aswell as the picture I can always remove the Alt Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918248 Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Do you mean using a CSS trick to show the text whilst images are disabled? For SEO purposes... Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918255 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 No No I just need to know how to get the title in aswell as the picture, so the title next to it still, then I can just take the Alt out of the Image script and It will have the Image and the text, and if there is no Image, then the text will still show Thanks Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918258 Share on other sites More sharing options...
Adam Posted September 14, 2009 Share Posted September 14, 2009 Oh okay, just need to jiggle it around a little.. echo '<td><a href="' . $scripturl . '?action=downloads;sa=view;down=' . $file['ID_FILE'] . '"><img src="/images/' . $file['title'] . '.png" alt="" />' . $file['title'] . '</a></td>'; Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918260 Share on other sites More sharing options...
Marsha Posted September 14, 2009 Author Share Posted September 14, 2009 Thats the one I did try myself but there is only so long until somebody complains that I keep making errors come up on the site hehe! Thanks very much kind sir! Solved Marshall P.S. Your a Genius Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918263 Share on other sites More sharing options...
Marsha Posted September 15, 2009 Author Share Posted September 15, 2009 Hey, Sorry to bring back a sort of old topic, but I thought it was better to give you a sense of what I am doing I have the same type of code echo '<td align="center"><a href="' . $scripturl . '?action=downloads;sa=view;down=' . $row['ID_FILE'] . '">',$row['title'],'</a><br />'; apart from the $row['title'] is the same as the $file['title']. What I have is lots of pictures that are named exactly the same as the title, and I need them to come up when I hover over the title... those images are kept at the directory /images/. What MrAdam gave me was perfect for what I needed and I will be keeping that on one page but this page is a little more pushed for space, so I need a Hover Over button, so when you hover over the $row['title'] it shows a picture from /images/$row['title'].png (.png at the end is fairly important lol) I have a code already for this but I cannot seem to merge it, I am very bad at php lol! Here is the Body code I have <body> <a id="hoverover" style="cursor:default;" onMouseOver="ShowPopup(this);" onMouseOut="HidePopup();">South West Trains</a> <div id="hoverpopup" style="visibility:hidden; position:absolute; top:0; left:0;"> <img src="http://rs-trainsim.co.uk/forums/downloads/catimgs/1.png"></font></td></tr> </div></body> That is for the pop-up I think I explained that well... Thanks for reading and any help or questions are helpful Marshall Quote Link to comment https://forums.phpfreaks.com/topic/174174-solved-need-help-adding-image-to-php-code/#findComment-918716 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.