| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Buried in cloud files? We can help with Spring cleaning!

    Whether you use Dropbox, Drive, G-Suite, OneDrive, Gmail, Slack, Notion, or all of the above, Dokkio will organize your files for you. Try Dokkio (from the makers of PBworks) for free today.

  • Dokkio (from the makers of PBworks) was #2 on Product Hunt! Check out what people are saying by clicking here.

View
 

10gbPHPTeacher

Page history last edited by PBworks 15 years ago

 10 Green Bottles - PHP (with a little bit of html)

 

First asks how many bottles to sit on the wall and then proceeds.  Even includes bottle pictures but can be removed if it begins to take too long.  I tried with 1000 bottles and gave up!

 

<?php

if (isset($_POST['numbottles'])) {

  $numbottles = ((int)$_POST['numbottles']);

 

for ($i = $numbottles; $i >= 1; $i--){

    for ($j = 1; $j <= $i; $j++){

        echo  "<img src=\"green_bottle.png\" />";

        }

    echo "<BR>";

    if ($i == 1)

    {

        echo $i." green bottle sitting on the wall!<BR>";

        echo $i." green bottle sitting on the wall!<BR>";

        echo "And if one green bottle should accidentally fall<BR>";

        echo "There'll be no green bottles sitting on the wall!<BR>";

        echo "<BR>";

    } else

    {

        echo $i." green bottles sitting on the wall!<BR>";

        echo $i." green bottles sitting on the wall!<BR>";

        echo "And if one green bottle should accidentally fall<BR>";

        if ($i-1 == 1)

        {

            echo "There'll be ".($i-1)." green bottle sitting on the wall!<BR>";

        } else

        {

            echo "There'll be ".($i-1)." green bottles sitting on the wall!<BR>";

        }

        echo "<BR>";

    }

}

echo "<a href=\"10gb.php\">Reset the bottles on the wall and start again.</a>";

} else

{

?>

<form id="form1" name="form1" method="post" action="10gb.php">

  <p>How many bottles to you want to begin with on the wall?</p>

  <p>

    <input name="numbottles" type="int" id="numbottles" />

    <input type="submit" name="Submit" value="Submit" />

  </p>

</form>

<p>

<?php

}

?>

 

Download

Comments (0)

You don't have permission to comment on this page.