You are on page 1of 6

EXNO:-3 DATE:STUDENT INFORMATION USING ARRAY OF CLASS OBJECT AIM:-To write a program to get and display the student

details using array of objects. ALGORITHM:Step 1: Open the XAMPP control panel. Step 2: open the notepad and create arrayget.php file Step 3: create the session name as my. Step 4 :create a class name as person. Step 5 :define the setfuncitons to access the datas. Step 6 :define the displaydata() function to display the datas. Step 7: create an object for person class to call the functions. Step 8: define the object to the array name as myArray[]. Step 9: declare the myArray[] in to the session. Step10:use unset function if the radiobutton is not empty. Step11:create a variable called count to retrieve the number of records. Step12:define the html code to access the details of the student. Step13:display the record using foreach() condition. Step14:delete the record when the radiobutton is clicked. Step15:save the program and run the program. Step16:Finish

SOURCE CODE:Arrayget.php <?php session_start(); $myArray = $_SESSION['my']; $name = trim($_POST['textfield1']); $regno = trim($_POST['textfield2']); $phone = trim($_POST['textfield3']); $age = trim($_POST['textfield4']); $dept = trim($_POST['textfield5']); $mark1 = trim($_POST['textfield6']); $mark2 = trim($_POST['textfield7']); $mark3 = trim($_POST['textfield8']); $rb = trim($_POST['radiobutton']); class Person { public $name; public $regno; public $phone;

public $age; public $dept; public $mark1; public $mark2; public $mark3; function setname($name) { $this->name = trim($name); } function setregno($regno) { $this->regno = trim($regno); } function setphone($phone) { $this->phone = trim($phone); } function setage($age) { $this->age = trim($age); } function setdept($dept) { $this->dept = trim($dept); } function setmark1($mark1) { $this->mark1 = trim($mark1); } function setmark2($mark2) { $this->mark2 = trim($mark2); } function setmark3($mark3) { $this->mark3 = trim($mark3); }

function displayData() { $t=$this->mark1+$this->mark2+$this->mark3; return "<td>$this->name</td><td>$this->regno</td> <td>$this->phone</td><td>$this->age</td> <td>$this->dept</td><td>$this->mark1</td>

<td>$this->mark2</td><td>$this->mark3</td><td>$t</td>"; } } if ($name != "" ) { $person = new Person(); $person->setname($name); $person->setregno($regno); $person->setphone($phone); $person->setage($age); $person->setdept($dept); $person->setmark1($mark1); $person->setmark2($mark2); $person->setmark3($mark3); echo $message = "<p><strong>Created a new Person.</strong></p>\n"; $myArray[] = $person; $_SESSION['my'] = $myArray; } if ($rb <> "") { unset($myArray[$rb]); $_SESSION['my'] = $myArray; } $count = count($myArray); ?> <html> <body> <table border="1" cellpadding="4" cellspacing="0"> <tr valign="top"> <td> </td> <td> <h1>Array of Class Objects</h1> <form name="form1" method="post" action="arrayget.php"> <table border="1" cellspacing="0" cellpadding="4">a <tr> <td><div align="right">Name:</div></td> <td> <input type="text" name="textfield1"> </td> </tr> <tr> <td><div align="right">Reg&nbsp;No:</div></td> <td> <input type="text" name="textfield2"> </td> </tr> <tr>

<td><div align="right">Phone:</div></td> <td> <input type="text" name="textfield3"> </td> </tr> <tr> <td><div align="right">Age:</div></td> <td> <input type="text" name="textfield4"> </td> </tr> <tr> <td><div align="right">Department:</div></td> <td> <input type="text" name="textfield5"> </td> </tr> <tr> <td><div align="right">Mark1:</div></td> <td> <input type="text" name="textfield6"> </td> </tr> <tr> <td><div align="right">Mark2:</div></td> <td> <input type="text" name="textfield7"> </td> </tr> <tr> <td><div align="right">Mark3:</div></td> <td> <input type="text" name="textfield8"> </td> </tr> <tr> <td colspan="2"><div align="right"> <input type="submit" name="Submit" value="Insert"> </div> </td> </tr> </table> </form>

<?php echo "<p>Record count = $count</p>\n"; echo "<form name=\"form2\" method=\"post\" action=\"arrayget.php\">\n"; echo "<table border=\"1\" cellpadding=\"9\" border=\"1\" cellspacing=\"0\">\n"; echo "<tr><td><h3>Delete</h3></td>\n"; echo "<td><h3>Record #</h3></td>\n"; echo "<td><h3> Name</h3></td>\n"; echo "<td><h3>Reg No</h3></td>\n"; echo "<td><h3> Phone</h3></td>\n"; echo "<td><h3> Age</h3></td>\n"; echo "<td><h3> Dept</h3></td>\n"; echo "<td><h3>Mark1</h3></td>\n";

echo "<td><h3> Mark2</h3></td>\n"; echo "<td><h3> Mark3</h3></td>\n"; echo "<td><h3> Total</h3></td>\n"; { foreach($myArray as $key => $value) { echo "<tr><td><input name=\"radiobutton\" type=\"radio\" value=\"$key\"></td>\n"; echo "<td align=\"center\">$key</td>".$value->displayData()."</tr>\n"; } } echo "<tr><td colspan=\"9\" align=\"right\">\n"; echo "<input type=\"submit\" name=\"Delete\" value=\"Delete\">\n"; echo "</td></tr>\n"; echo "</table>\n"; echo "</form>\n"; ?> </td> </tr> </table> </body> </html> OUTPUT:-

RESULT:Thus the program has been executed successfully and verified.

You might also like