Jump to content

switch statement and loop not working


Ruth

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;

 

}

}

 

?>

 

Link to comment
Share on other sites

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.