Jump to content

Recommended Posts

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

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.

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'";

 

 

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?

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?

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.