Tribhuwan University

Institute of Science and Technology

2078

Bachelor Level / Third Year / Fifth Semester / Science

B.Sc in Computer Science and Information Technology (CSC329)

(Web Technology)

Full Marks: 60

Pass Marks: 24

Time: 3 Hours

Candidates are required to give their answers in their own words as for as practicable.

The figures in the margin indicate full marks.

Section A

Long Answers Questions

Attempt any TWO questions.
[2*10=20]
1.
How do you define an Array in PHP? write a PHP script to create a multidimensional array name Product that will contain pcode, pname, and price. Initialize the array with at least three instances. Also, Write an HTML script to display the initialized values of the array in an HTML Table.[10]

How to Define an Array in PHP with Multidimensional Array Example

Array in PHP is a special variable that can hold multiple values of same or different data types under a single name, accessed using index or key.


Definition of Array in PHP

An array is a data structure that stores one or more similar or dissimilar type of values in a single variable. In PHP, arrays can be defined in two ways:

  • Using the array() function: $arr = array("value1", "value2", "value3");
  • Using short syntax (square brackets): $arr = ["value1", "value2", "value3"];

Types of Arrays in PHP:

  • Indexed Array – Arrays with numeric index (starting from 0)
  • Associative Array – Arrays with named keys
  • Multidimensional Array – Arrays containing one or more arrays inside them

PHP Script to Create Multidimensional Array "Product"

A multidimensional array is an array of arrays. Here, each element of the main array is itself an associative array containing pcode, pname, and price.

<?php
    // Defining a multidimensional array named Product
    $Product = array(
        array("pcode" => "P001", "pname" => "Laptop", "price" => 45000),
        array("pcode" => "P002", "pname" => "Mouse", "price" => 500),
        array("pcode" => "P003", "pname" => "Keyboard", "price" => 1200)
    );
?>

Complete HTML + PHP Script to Display Array in an HTML Table

<!DOCTYPE html>
<html>
<head>
    <title>Product Table</title>
</head>
<body>

<h2>Product Details</h2>

<table border="1" cellpadding="10" cellspacing="0">
    <tr>
        <th>Product Code</th>
        <th>Product Name</th>
        <th>Price (Rs.)</th>
    </tr>

    <?php
        // Defining multidimensional array
        $Product = array(
            array("pcode" => "P001", "pname" => "Laptop", "price" => 45000),
            array("pcode" => "P002", "pname" => "Mouse", "price" => 500),
            array("pcode" => "P003", "pname" => "Keyboard", "price" => 1200)
        );

        // Displaying array values in table rows using loop
        for($i = 0; $i < count($Product); $i++)
        {
            echo "<tr>";
            echo "<td>" . $Product[$i]["pcode"] . "</td>";
            echo "<td>" . $Product[$i]["pname"] . "</td>";
            echo "<td>" . $Product[$i]["price"] . "</td>";
            echo "</tr>";
        }
    ?>

</table>

</body>
</html>

Output (HTML Table)

Product Code Product Name Price (Rs.)
P001 Laptop 45000
P002 Mouse 500
P003 Keyboard 1200

Key Points to Remember

  • count($Product) returns the number of elements (3 in this case)
  • Each row of the array is accessed using numeric index $Product[$i]
  • Each column is accessed using associative key like $Product[$i]["pcode"]
  • The for loop iterates through all instances and generates table rows dynamically
  • Multidimensional arrays are ideal for representing structured data like database records

Conclusion: Arrays in PHP are powerful data structures. Multidimensional arrays allow us to store complex data like product catalogs, and when combined with HTML, we can display this data in a well-formatted table on a webpage.

2.
Create an HTML signup form with fields Name, Email, Password, and Age. Validate the form using JavaScript. Write functions for validating each of the elements. All of the fields should not be empty. The Email address should be a valid email, the password should be of length at least 6 and should start with the alphabet and end with a digit. The age should be between 8 and 60.[10]
3.
How external CSS is inserted in an HTML page? Create an HTML page with two paragraph tags with id p1 and p2, and one div tag with id dv1. Write an external CSS file as per the description. the margin of the paragraphs should be 100px from the top and 80px from the left. Both of paragraphs should have the display set to block. The dv1 should have padding left and right set to 30px and 25px respectively, its background color should be blue and the font color should be red with the font type Verdana. Set the display of dv1 to none.[10]
Section B

Short Answers Questions

Attempt any Eight questions.
[8*5=40]
4.
What are the services provided under web2.0? [5]
5.
How jQuery id selector can be used to select specific element? Write an example with jQuery that will hide a paragraph on clicking a button. [5]
6.
Discuss about different JSON data types. [5]
7.
What is DTD? Create a XML file and write its equivalent DTD. [5]
8.
How can you define function in PHP? Create a function that will take two integers as argument and will return product of them. [5]
9.
Describe CSS Box model with example. [5]
10.
Create an HTML page with its body containing a div. The div should contain an image within it. Create a link on the image to redirect to the url http://www.tuiost.edu.np. Set the title of the page to “iost”. Add Meta tag on the page. [5]
11.
Create a HTML page containing ordered and unordered lists. Set the value of ordered list type to 'A'. The list should start at 'D'. [5]