Question

In: Computer Science

write a script that will output a table where the rows and cells are labeled the...

  • write a script that will output a table where the rows and cells are labeled
  • the script should be versatile so one can change the number of rows and cells the script outputs
  • have the script create a table with 15 rows and 5 cells
  • refer to the tables lesson for info on how to create a table
  • you need to write all the PHP functionality above the doctype and display the remaining HTML string via a variable in the echo statement within the body element

in PHP/HTML

Solutions

Expert Solution

PHP File :rowsCols.php

<!-- PHP Functionality -->

<?php

    if(isset($_POST['btnRowsCols']))

    {

        //number of rows entered by user

        $rows=$_POST['txtRows'];

        //number of columns entered by user

        $cols=$_POST['txtColumns'];

        //declaring variable to store table

        $htmlTable="<table border=1>";

        //using for loop

        //this for loop is used for number of rows

        for($i=1;$i<=$rows;$i++)

        {

            $htmlTable= $htmlTable."<tr>";//creating row

        //this for loop is used for number of columns

        for($j=1;$j<=$cols;$j++)

        {

            //creating cell

            $htmlTable=$htmlTable."<td>R".$i." C".$j."</td>";

        }

        $htmlTable=$htmlTable."</tr>";//close row

        }

        //closing of the table

        $htmlTable=$htmlTable."</table>";

        //display table on the web page

        echo $htmlTable;

    }

?>

<!DOCTYPE html>

<html lang="en">

    <head>

        <!-- title for web page -->

        <title>PHP Table</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1">

       

    </head>

    <body>

    <form action="rowsCols.php" method="post">

    Enter number of rows :

    <!-- textbox for number of rows -->

    <input type="text" name="txtRows"/>

    <br><br>

    Enter number of columns/cells :

    <!-- textbox for number of columns/cells -->

    <input type="text" name="txtColumns"/>

    <br><br>

    <!-- button to submit form -->

    <input type="submit" name="btnRowsCols"/>

    </form>

    </body>

</html>

======================================

Screen asking rows and columns :

Screen showing table :


Related Solutions

Write a script that will output a table where the rows and cells are labeled. The...
Write a script that will output a table where the rows and cells are labeled. The script should be versatile, so one could easily change the number of rows and cells the script should output. For this exercise have the script create a table with 15 rows and 5 cells. Refer to the tables lesson for information on how to create a table. You need to write all the PHP functionality above the doctype and display the resulting HTML string...
Write a script to display the following patterns on the screen. Number of rows and columns...
Write a script to display the following patterns on the screen. Number of rows and columns are taken from the command arguments; if they are missing, set default to 3 (rows) and 4 (columns). Hint: you will use a nested loop. **** **** **** a) Display the source code in an editor (#4-11) b) Execute your script in the terminal, and display the command and the result (#4-12)
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter...
Using Bash script, 1. Print the multiplication table upto 10 rows. Ask the user to enter a number. say user enters 10, your output should be : [srivatss@athena shell]> ./mult.sh I will be printing the multiplication table Please enter a number 10 1 x 10 = 10 2 x 10 = 20 3 x 10 = 30 4 x 10 = 40 5 x 10 = 50 6 x 10 = 60 7 x 10 = 70 8 x 10...
modify code to write the output as an HTML table to a file in the output...
modify code to write the output as an HTML table to a file in the output directory. The file that is saying to work at : SOURCE CODE IN PERL: print "Enter principal amount: "; $P=; while($P<=0) { print "Principal must be positive. Try again: "; $P=; } print "Enter number of times interest is applied in a year: "; $n=; while($n!=12 && $n!=4 && $n!=2 && $n!=1) { print "It must be 12, 4, 2 or 1. Try again:...
Imagine the year is 2116, and the periodic table has been expanded to 25 rows. Write...
Imagine the year is 2116, and the periodic table has been expanded to 25 rows. Write a set of four quantum numbers for the outermost election of the halogen in the last row.
Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result:             25   69   51   26 171...
Write a Python program which adds up columns and rows of given table as shown in...
Write a Python program which adds up columns and rows of given table as shown in the specified figure. Example test case (the four lines below “Input cell value” are input from user, and the five lines below “Results:” are the output of the program.): Input number of rows/columns (0 to exit) 4 Input cell value: 25 69 51 26 68 35 29 54 54 57 45 63 61 68 47 59 Result: 25 69 51 26 171 68 35...
I need a copy of organized data in a spreadsheet with rows and columns labeled, can...
I need a copy of organized data in a spreadsheet with rows and columns labeled, can anyone help me with this please? I am doing a made up experiment where I see if eating vegetarian diets makes someone healthier. I am ‘supposed’ to find a group of people at school willing to participate and change their diet, pull their names from a jar, and randomly assign who will try the vegetarian diet and who’s diet will remain the same that...
Summary Lewis wants you to write another script that shows a table of events at the...
Summary Lewis wants you to write another script that shows a table of events at the Lyman Hall Theater over the next two weeks from the current date. He has already created three arrays for use with the script: The eventDates array containing a list of dates and times at which theater events are scheduled. The eventDescriptions array containing the description of those events. The eventPrices array containing the admission prices of those events. Lewis has already written the page...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n'...
Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n' (nxn chart).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT