Ruth Posted March 26, 2008 Share Posted March 26, 2008 for($rating_num; $rating_num <= 5; $rating_num++) { switch($rating) { case 'star': echo '<img src = "images/star.gif">'; break; } } I have a drop down box that will give a numeric rating($rating_num) 1-5. When I select 5 it will display 1 start, when I select 1 it will display 5 starts. It seems to be running backward. Any ideas on how to fix this? $rating is the way the user wishes to display the rating stars, thumbs up, or numeric. Quote Link to comment Share on other sites More sharing options...
r-it Posted March 26, 2008 Share Posted March 26, 2008 for($rating_num = 1; $rating_num <= 5; $rating_num++) { switch($rating) { case 'star': echo '<img src = "images/star.gif">'; break; } } Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 26, 2008 Share Posted March 26, 2008 the use of a switch on a single condition is pretty pointless try <?php for($rating_number = 1; $rating_num <= 5; $rating_num++} if($rating[$rating_number] == "star"){ echo "<img src=\"images/star.gif\" alt=\"star\" />"; } else{ #echo No star img } } ?> Quote Link to comment Share on other sites More sharing options...
Ruth Posted March 26, 2008 Author Share Posted March 26, 2008 for($rating_num = 1; $rating_num <= 5; $rating_num++) { switch($rating) { case 'star': echo '<img src = "images/star.gif">'; break; } } I tired this and no matter which number I select I get 5 stars. I've also tired $rating_num = 0 and get the same result Quote Link to comment Share on other sites More sharing options...
Ruth Posted March 26, 2008 Author Share Posted March 26, 2008 There will be more then one condition I'm just trying to get this one to work before I start adding more. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted March 26, 2008 Share Posted March 26, 2008 well of course u get 5 stars or no stars the var $rating isn't defined in what we see so if it is "star" it will always be true you need to show more code Quote Link to comment Share on other sites More sharing options...
Ruth Posted March 26, 2008 Author Share Posted March 26, 2008 Here is my entire code $movie = $_POST['movie']; $rating = $_POST['rating']; $rating_num = $_POST['rating_num']; $comment = $_POST['comments']; echo "Move: $movie <br />"; for($rating_num=1; $rating_num <= 5; $rating_num++) { switch($rating) { case 'star': echo '<img src = "images/star.gif">'; break; } } The rating is being defined in the post Quote Link to comment Share on other sites More sharing options...
Ruth Posted March 26, 2008 Author Share Posted March 26, 2008 Forgot to take out a suggestion I tired here is my orginal code <?php $movie = $_POST['movie']; $rating = $_POST['rating']; $rating_num = $_POST['rating_num']; $comment = $_POST['comments']; echo "Move: $movie <br />"; for($rating_num; $rating_num <= 5; $rating_num++) { switch($rating) { case 'star': echo '<img src = "images/star.gif">'; break; } } ?> Quote Link to comment Share on other sites More sharing options...
Ruth Posted March 26, 2008 Author Share Posted March 26, 2008 Is anyone still out there? No matter where I look nothing has a good suggestion for how to get this to work correctly. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Your for statement does not make sense. It should be: for($i=0; $i < $rating_num; $i++) I presume rating_num determines how many stars are shown. Quote Link to comment Share on other sites More sharing options...
Ruth Posted March 26, 2008 Author Share Posted March 26, 2008 Your wonderful I didn't know you could use $i by itself I thought you had to set it to something. Very cool thanks so much. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 26, 2008 Share Posted March 26, 2008 Umm, $i is set to 0 for($i=0; ... ) You may need to read up on how a for loop works. 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.