yogibear Posted July 28, 2007 Share Posted July 28, 2007 Hi all a question about storing image paths in a database I will have hundreds of images stored in an images folder. I have 14 columns in my database and the information in each changes which picture that is displayed. All the images will be .jpg and have file names like Vauxhall Corsa_Red_1_2_1_2_1_2_1_1_1_2_2_1.jpg This is what I have, I tried I few different things but I have removed them to make it less confusing for me and easier to explain, hopefully. $img = "<img src='/images/$car_$colour_$alloys'.jpg>"; { echo $img; } the above code should only display Vauxhall Corsa_Red_1.jpg which I have made for a test can someone tell me what is wrong with my code I know it is very wrong? Many thanks and thanks in advance Yogi Link to comment https://forums.phpfreaks.com/topic/62223-solved-image-paths/ Share on other sites More sharing options...
MatMel Posted July 28, 2007 Share Posted July 28, 2007 The ' has to be after .jpg, because .jpg is part of the path... If that doesn't solve the problem, you will have to tell us, where the variables $car, $colour and $alloys come from. Link to comment https://forums.phpfreaks.com/topic/62223-solved-image-paths/#findComment-309730 Share on other sites More sharing options...
yogibear Posted July 28, 2007 Author Share Posted July 28, 2007 while($row = mysql_fetch_array($result)) $car = $row['car']; $colour = $row['colour']; $alloys = $row['alloys']; $img = "<img src='/images/$car_$colour_$alloys.jpg'>"; { echo $img; } Thank you for your reply I still have the same problem this is the current code when i open the page and right click where the image should be and click properties the URL that is shown is http://www.***.co.uk/images/.jpg> Link to comment https://forums.phpfreaks.com/topic/62223-solved-image-paths/#findComment-309767 Share on other sites More sharing options...
MatMel Posted July 28, 2007 Share Posted July 28, 2007 Ok ... php probably thinks that $car_$colour_$alloys is one variable. Try $img = "<img src='/images/" . $car . "_" . $colour . "_" . $alloys. ".jpg'>"; If that still doesn't work, you will have to check: 1. are the data stored in the database correct? 2. is the query performed correctly? Link to comment https://forums.phpfreaks.com/topic/62223-solved-image-paths/#findComment-309781 Share on other sites More sharing options...
yogibear Posted July 29, 2007 Author Share Posted July 29, 2007 Hi It almost works I think that it’s this bit because it now displays $car and if I swap the position of $colour with $car $colour then works but $car doesn’t, it is only the first line that works. I have also tried echo $car; and echo $colour; and get the same results. Is there something that is meant to go between these lines of code? $car = $row['car']; $colour = $row['colour']; $alloys = $row['alloys']; Many thanks Yogi Link to comment https://forums.phpfreaks.com/topic/62223-solved-image-paths/#findComment-309992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.