Wednesday, 18 May 2016

Design a web page using PHP which will print different patterns according to user choice.

<html>
    <head>
        <meta charset="UTF-8">
        <title>Pattern</title>
    </head>
    <body>
        <form action="" method="post">
        <h1><u>PHP project to print patterns</u></h1>
       
        <h3>Please choose a pattern to print</h3>
        1.<image src="1.jpg"/> &nbsp;
        2.<image src="2.jpg"/> &nbsp;
        3.<image src="3.jpg"/> &nbsp;<br/><br/>
        Enter your choice : <input type="text" name="pat"/><br/><br/>
        Enter no of rows : <input type="text" name="r"/><br/><br/>
        <br/><input type="submit" name="btn" value="Print Pattern"/><br/><br/>
        <?php
           
            if(isset($_POST['btn']))
            {
                $n= $_POST['r'];
                if($_POST['pat']==1)
                {
                    for($x=0;$x<=$n;$x++)
                    {
                        for($y=1;$y<=$x;$y++)
                        {
                            echo "*";
                        }
                        echo "<br>";
                    }
                }
                elseif ($_POST['pat']==2)
                    {
                        for($x=$n;$x>=1;--$x)
                    {
                        for($y=1;$y<=$x;++$y)
                        {
                            echo "*";
                        }
                        echo "<br>";
                    }
               
                    }
                    elseif ($_POST['pat']==3) {
                       
                       $temp=$n;
                        for($row=1;$row<=$n;$row++)
                        {
                            for($c=1;$c<$temp;$c++)
                            {
                                echo "&nbsp ";
                            }
                            $temp--;
                            for ($c = 1; $c <= 2 * $row - 1; $c++) {
                                    echo "*";
                            }
                            echo "<br>";
                        }
                    }
                    else
                        echo "<br/>Invalid Input!!!";
            }
           
           
        ?>
        </form>
    </body>
</html>

No comments:

Post a Comment