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

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

10gbPHPTeacher

Page history last edited by PBworks 16 years, 6 months 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.