toxictoad Posted June 11, 2008 Share Posted June 11, 2008 Hey all, I'm, working on my movie database and I'm trying to work out how to show images and have them changed based on what's entered in to the DB e.g. each film has my own 'Star Rating' from 1-5, if the film gets a 1 then the web page should display 1star.gif, 2star.gif for 2 stars etc. At the mo the page just shows the number using this code: $dvd_field_5 Shown like this is the page code: <td align=\"center\" nowrap><font size=\"2\" color=\"$dvd_text_color\">$dvd_field_5</font></td> So how would I best go about getting this to work? thanks Link to comment https://forums.phpfreaks.com/topic/109766-changing-images-based-on-number-entered/ Share on other sites More sharing options...
conker87 Posted June 11, 2008 Share Posted June 11, 2008 You should use javascript. This is what I have for something similar: Rate:<br> <select size="1" name="rate" onchange="document.getElementById('rate_pic').src='/images/'+this.value+'_stars.png';"> <option value="">Choose</option> <option value="">----------------</option> <option>0.0</option><option>0.5</option><option>1.0</option><option>1.5</option><option>2.0</option><option>2.5</option> <option>3.0</option><option>3.5</option><option>4.0</option><option>4.5</option><option>5.0</option><option>5.5</option> <option>6.0</option><option>6.5</option><option>7.0</option><option>7.5</option><option>8.0</option><option>8.5</option> <option>9.0</option><option>9.5</option><option>10.0</option> </select>/10 <img scr="/images/0.0_stars.png" id="rate_pic" height="12" width="100"> Obviously, just change the forum and image source to your own. Link to comment https://forums.phpfreaks.com/topic/109766-changing-images-based-on-number-entered/#findComment-563281 Share on other sites More sharing options...
.josh Posted June 11, 2008 Share Posted June 11, 2008 so..you're wanting your movies to have a rating, 1-5, and there's a column in your database table that specifies that, and you want to be able to get the rating, and display the correct amount of stars? Is your star image just a single image that you display x amount of them based on rating? Make a loop. Do you have 5 different images, one for each rating? If they are all named like 1star.gif, 2star.gif, 3star.gif, etc.. then simply concat the rating onto "star.gif" like // retrieve rating from db and put it into $rating echo "<img src = '{$rating}star.gif'"; Link to comment https://forums.phpfreaks.com/topic/109766-changing-images-based-on-number-entered/#findComment-563290 Share on other sites More sharing options...
toxictoad Posted June 11, 2008 Author Share Posted June 11, 2008 Can I see this in operation? - To conker87 I guess I could just have a link to a different image right? so instead of the field having "1" - "5" it would be "stars/1.gif" - "stars/2.gif" then instead of this code <font size=\"2\" color=\"$dvd_text_color\">$dvd_field_5</font> I would have this: <img src=\"$dvd_field_5\" width=\"10\" height=\"5\"> Would that work or create problems? Link to comment https://forums.phpfreaks.com/topic/109766-changing-images-based-on-number-entered/#findComment-563298 Share on other sites More sharing options...
toxictoad Posted June 11, 2008 Author Share Posted June 11, 2008 so..you're wanting your movies to have a rating, 1-5, and there's a column in your database table that specifies that, and you want to be able to get the rating, and display the correct amount of stars? Is your star image just a single image that you display x amount of them based on rating? Make a loop. Do you have 5 different images, one for each rating? If they are all named like 1star.gif, 2star.gif, 3star.gif, etc.. then simply concat the rating onto "star.gif" like // retrieve rating from db and put it into $rating echo "<img src = '{$rating}star.gif'"; Yes I was going to create 5 images each with an extra star highlighted so I think what you're suggesting will work good. Am I right in thinking that the images would be in the same folder as the php script? if they're not would "<img src= images/'{$rating}star.gif"; work just as well? Link to comment https://forums.phpfreaks.com/topic/109766-changing-images-based-on-number-entered/#findComment-563310 Share on other sites More sharing options...
conker87 Posted June 11, 2008 Share Posted June 11, 2008 You can do that. cho "<img src='images/{$rating}star.gif"; Link to comment https://forums.phpfreaks.com/topic/109766-changing-images-based-on-number-entered/#findComment-563319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.