Guest User

Web Programs 1-10

a guest
Dec 11th, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.39 KB | None | 0 0
  1. Program 1-------------------------------------------------------------------------------------------------------------------------
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <style>
  6. table,td,th {
  7. border : 1px solid black;
  8. width: 33%;
  9. text-align: center;
  10. background-color: darkgray;
  11. border-collapse: collapse;
  12. }
  13. table {
  14. margin: auto;
  15. }
  16. input {
  17. text-align: right;
  18. }
  19. </style>
  20.  
  21. <script type="text/javascript">
  22. function calc(clicked_id) {
  23. var val1 = parseFloat(document.getElementById("value1").value);
  24. var val2 = parseFloat(document.getElementById("value2").value);
  25. if(isNaN(val1)||isNaN(val2))
  26. alert("ENTER VALID NUMBER")
  27. else if(clicked_id == "add")
  28. document.getElementById("answer").value=val1+val2;
  29. else if(clicked_id == "sub")
  30. document.getElementById("answer").value=val1-val2;
  31. else if(clicked_id == "mul")
  32. document.getElementById("answer").value=val1*val2;
  33. else if(clicked_id == "div")
  34. document.getElementById("answer").value=val1/val2;
  35. }
  36.  
  37. function cls() {
  38. value1.value = "0";
  39. value2.value = "0";
  40. answer.value = "";
  41. }
  42. </script>
  43. </head>
  44. <body>
  45.  
  46. <table>
  47. <tr>
  48. <th colspan="4">SIMPLE CALCULATOR</th>
  49. </tr>
  50. <tr>
  51. <td>value1</td>
  52. <td><input type="text" id="value1" value="0"></td>
  53. <td>value2</td>
  54. <td><input type="text" id="value2" value="0"></td>
  55. </tr>
  56. <tr>
  57. <td><input type="button" value="Addition" id="add" onclick="calc(this.id)"></td>
  58. <td><input type="button" value="Subtraction" id="sub" onclick="calc(this.id)"></td>
  59. <td><input type="button" value="Multiplication" id="mul" onclick="calc(this.id)"></td>
  60. <td><input type="button" value="Division" id="div" onclick="calc(this.id)"></td>
  61. </tr>
  62. <tr>
  63. <td>Answer : </td>
  64. <td><input type="text" id="answer" value="" disabled></td>
  65. <td colspan="2"><input type="button" value="CLEAR ALL" onclick="cls()"></td>
  66. </tr>
  67. </table>
  68.  
  69. </body>
  70. </html>
  71. Program 2-------------------------------------------------------------------------------------------------------------------------
  72. <!DOCTYPE html>
  73. <html lang="en">
  74. <head>
  75. <style>
  76. table,tr,td {
  77. border : solid black;
  78. width: 33%;
  79. text-align: center;
  80. border-collapse: collapse;
  81. background-color: lightblue;
  82. }
  83. table {
  84. margin: auto;
  85. }
  86. </style>
  87.  
  88. <script>
  89. document.write("<table><tr><th colspan='3'> NUMBER FROM 0 TO 10 WITH THEIR SQUARES AND CUBES</th></tr>");
  90. document.write("<tr><td>Number</td><td>Square</td><td>Cube</td></tr>");
  91. for(var n=0;n<=10,n++) {
  92. document.write("<tr><td>" + n + "</td><td>" + n*n + "</td><td>" + n*n*n + "</td></tr>");
  93. }
  94. document.write("</table>")
  95. </script>
  96. </head>
  97. <body>
  98.  
  99. </body>
  100. </html>
  101. Program 3-------------------------------------------------------------------------------------------------------------------------
  102. <!DOCTYPE html>
  103. <html lang="en">
  104. <head>
  105. <style>
  106. p {
  107. position: absolute;
  108. top: 50%;
  109. left: 50%;
  110. transform: translate(-50%,-50%);
  111. }
  112. </style>
  113. </head>
  114. <body>
  115. <p id="demo"></p>
  116. <script>
  117. var var1 = setInterval(inTimer, 1000);
  118. var fs =5;
  119. var ids = document.getElementById("demo");
  120. function inTimer() {
  121. ids.innerHTML = "TEXT GROWING";
  122. ids.setAttribute('style',"font-size:" + fs + "px; color:red");
  123. fs +=5;
  124. if(fs >=50) {
  125. clearInterval(var1);
  126. var var2 = setInterval(deTimer, 1000);
  127. }
  128. }
  129.  
  130. function deTimer() {
  131. fs -= 5;
  132. ids.innerHTML = "TEXT SHRINKING";
  133. ids.setAttribute('style',"font-size:" + fs + "px;color:blue");
  134. if(fs == 5) {
  135. clearInterval(var2);
  136. }
  137. }
  138. </script>
  139. </body>
  140. </html>
  141. Program 4-------------------------------------------------------------------------------------------------------------------------
  142. <!DOCTYPE html>
  143. <html lang="en">
  144. <head>
  145.  
  146. </head>
  147. <body>
  148. <script type="text/javascript">
  149. var str = prompt("Enter the input : ","");
  150. if(!isNaN(str)) {
  151. var num,rev=0,remainder;
  152. num=parseInt(str);
  153. while(num!=0) {
  154. remainder = num%10;
  155. num = parseInt(num/10);
  156. rev = rev*10+remainder;
  157. }
  158. alert("Reverse of " + str + " is " + rev);
  159. }
  160.  
  161. else {
  162. str = str.toUpperCase();
  163. for(var i=0;i<str.length;i++) {
  164. var chr = str.charAt(i);
  165. if(chr== 'A' || chr == 'E' || chr =='I' || chr == 'O' || chr == 'U') break;
  166. }
  167. if(i<str.length)
  168. alert("The position of the left most vowel is " + (i+1));
  169. else
  170. alert("No vowel found in the entered string");
  171. }
  172. </script>
  173. </body>
  174. </html>
  175. Program 5css-------------------------------------------------------------------------------------------------------------------------
  176. student {
  177. display: block;
  178. margin-top: 10px;
  179. color: navy;
  180. }
  181.  
  182. USN {
  183. display: block;
  184. margin-top: 10px;
  185. font-size: 14pt;
  186. color: red;
  187. }
  188.  
  189. name {
  190. display: block;
  191. margin-top: 20px;
  192. font-size: 14pt;
  193. color: blue;
  194. }
  195.  
  196. college {
  197. display: block;
  198. margin-top: 20px;
  199. font-size: 12pt;
  200. color: maroon;
  201. }
  202.  
  203. branch {
  204. display: block;
  205. margin-top: 20px;
  206. font-size: 12pt;
  207. color: purple;
  208. }
  209.  
  210. year {
  211. display: block;
  212. margin-top: 20px;
  213. font-size: 14pt;
  214. color: green;
  215. }
  216.  
  217. e-mail {
  218. display: block;
  219. margin-top: 20px;
  220. font-size: 12pt;
  221. color: blue;
  222. }
  223. Program 5XML-------------------------------------------------------------------------------------------------------------------------
  224. <?xml-stylesheet type="text/css" href="5.css" ?>
  225. <!DOCTYPE html>
  226. <html>
  227. <head>
  228. <h1>STUDENTS DESCRIPTION</h1>
  229. </head>
  230. <students>
  231. <student>
  232. <USN>USN : 1AY07CS001</USN>
  233. <name>NAME : SANTHOSH</name>
  234. <college>COLLEGE : ACIT</college>
  235. <branch>BRANCH : COMPUTER SCIENCE AND ENGINEERING</branch>
  236. <year>YEAR : 2007</year>
  237. <e-mail>E-Mail : santhosh@gmail.com</e-mail>
  238. </student>
  239. <student>
  240. <USN>USN : 1AY07IS001</USN>
  241. <name>NAME : MANORANJAn</name>
  242. <college>COLLEGE : ACIT</college>
  243. <branch>BRANCH : INFORMATION SCIENCE AND ENGINEERING</branch>
  244. <year>YEAR : 2007</year>
  245. <e-mail>E-Mail : manoranjan@gmail.com</e-mail>
  246. </student>
  247. <student>
  248. <USN>USN : 1AY07EC001</USN>
  249. <name>NAME : CHETHAN</name>
  250. <college>COLLEGE : ACIT</college>
  251. <branch>BRANCH : ELECTRONICS AND COMMUNICATIONS ENGINEERING</branch>
  252. <year>YEAR : 2007</year>
  253. <e-mail>E-Mail : chethan@gmail.com</e-mail>
  254. </student>
  255. </students>
  256. </html>
  257. Program 6-------------------------------------------------------------------------------------------------------------------------
  258. <?php
  259. print "<h3> REFRESH PAGE</h3>";
  260. $name = "Counter.txt";
  261. $file = fopen($name,"r");
  262. $hits = fscanf($file,"%d");
  263. fclose($file);
  264.  
  265. $hits[0]++;
  266. $file=fopen($name,"w");
  267. fprintf($file,"%d",$hits[0]);
  268. fclose($file);
  269. print("Total number of views : ".$hits[0]);
  270. ?>
  271. Program 7-------------------------------------------------------------------------------------------------------------------------
  272. <!DOCTYPE html>
  273. <html lang="en">
  274. <head>
  275. <meta http-equiv="refresh" content="1"/>
  276. <style>
  277. p {
  278. color : white;
  279. font-size:90px;
  280. position : absolute;
  281. top:50%;
  282. left:50%;
  283. transform:translate(-50%,-50%);
  284. }
  285. body {
  286. background-color:black;
  287. }
  288. </style>
  289. <p><?php
  290. echo date(" h:i:s A");
  291. ?></p>
  292. </head>
  293. </html>
  294. Program 8a-------------------------------------------------------------------------------------------------------------------------
  295. <!DOCTYPE html>
  296. <html lang="en">
  297. <head>
  298. <style>
  299. table, td, th {
  300. border : 1px solid black;
  301. width : 33%;
  302. text-align:center;
  303. background-color:darkgray;
  304. }
  305. table {
  306. margin : auto;
  307. }
  308.  
  309. input,p {
  310. text-align : right;
  311. }
  312. </style>
  313. </head>
  314. <body>
  315. <form action="" method="POST">
  316. <table>
  317. <caption><h2>SIMPLE CALCULATOR</h2></caption>
  318. <tr>
  319. <td>First Number : </td>
  320. <td><input type="text" name="num1"></td>
  321. <td rowspan="2"><input type="submit" name="submit" value="calculate"></td>
  322. </tr>
  323. <tr>
  324. <td>Second Number : </td>
  325. <td><input type="text" name="num2"></td>
  326. </tr>
  327. </table>
  328. </form>
  329.  
  330. <?php
  331. if(isset($_POST['submit'])) {
  332. $num1 = $_POST['num1'];
  333. $num2 = $_POST['num2'];
  334. if(is_numeric($num1) and is_numeric($num2)) {
  335. echo "<tr><td> ADDITION : </td><td><p>".($num1+$num2)."</p></td>";
  336. echo "<tr><td> SUBTRACTION : </td><td><p>".($num1-$num2)."</p><td>";
  337. echo "<tr><td> MULTIPLICATION : </td><td><p>".($num1*$num2)."</p><td>";
  338. echo "<tr><td> DIVISION : </td><td><p>".($num1/$num2)."</p><td>";
  339. echo "</table>";
  340. }
  341. else {
  342. echo "<script type='text/javascript'>alert('Enter valid number');</script>";
  343. }
  344. }
  345. ?>
  346. </body>
  347. </html>
  348. Program 8b-------------------------------------------------------------------------------------------------------------------------
  349. <?php
  350.  
  351. $a = array(array(1,2,3),array(4,5,6),array(7,8,9));
  352. $b = array(array(7,8,9),array(4,5,6),array(1,2,3));
  353.  
  354. $m = count($a);
  355. $n = count($a[2]);
  356. $p = count($b);
  357. $q = count($b[2]);
  358.  
  359.  
  360. echo "The first matrix :"."<br/>";
  361. for($row = 0; $row < $m; $row++) {
  362. for($col = 0; $col < $n; $col++)
  363. echo " ".$a[$row][$col];
  364. echo "<br/>";
  365. }
  366.  
  367. echo "The second matrix :"."<br/>";
  368. for($row = 0; $row < $p; $row++) {
  369. for($col = 0; $col < $q; $col++)
  370. echo " ".$b[$row][$col];
  371. echo "<br/>";
  372. }
  373.  
  374. echo "The transpose for the first matrix is :"."<br/>";
  375. for($row = 0; $row < $m; $row++) {
  376. for($col = 0; $col < $n; $col++)
  377. echo " ".$a[$col][$row];
  378. echo "<br/>";
  379. }
  380.  
  381.  
  382. if(($m === $p) and ($n === $q)) {
  383. echo "The addition of matrices is : "."<br/>";
  384. for($row = 0; $row < 3; $row++) {
  385. for($col = 0; $col < 3; $col++)
  386. echo " ".$a[$row][$col]+$b[$row][$col]." ";
  387. echo "<br/>";
  388. }
  389. }
  390.  
  391.  
  392.  
  393. if($n === $p) {
  394. echo "The multiplication of Matrices : <br/>";
  395. $result = array();
  396. for($i = 0; $i < $m; $i++) {
  397. for($j = 0; $j < $q; $j++) {
  398. $result[$i][$j] = 0;
  399. for($k = 0; $k < $n; $k++)
  400. $result[$i][$j] += $a[$i][$k]*$b[$k][$j];
  401. }
  402. }
  403.  
  404. for($row = 0; $row < $m; $row++) {
  405. for($col = 0; $col < $q; $col++) {
  406. echo " ".result[$row][$col];
  407. }
  408. echo "<br/>";
  409. }
  410. }
  411. ?>
  412. Program 9-------------------------------------------------------------------------------------------------------------------------
  413. <?php
  414.  
  415. $states = "Mississippi Alabama Texas Massachusetts Kansas";
  416. $statesArray = [];
  417. $states1 = explode(' ',$states);
  418. echo "Original Array : <br/>";
  419. foreach($states1 as $i =>$value)
  420. print("STATES[$i]=$value <br/>");
  421. foreach($states1 as $state) {
  422. if(preg_match('/x as $/',($state)))
  423. $statesArray[0] = ($state);
  424. }
  425.  
  426. foreach($states1 as $state) {
  427. if(preg_match('/^k.*s$/',($state)))
  428. $statesArray[1] = ($state);
  429. }
  430.  
  431. foreach($states1 as $state) {
  432. if(preg_match('/^M.*s$/',($state)))
  433. $statesArray[2] = ($state);
  434. }
  435.  
  436. foreach($states1 as $state) {
  437. if(preg_match('/a$/',($state)))
  438. $statesArray[3] = ($state);
  439. }
  440.  
  441. echo "<br><br> Resultant Array : <br>";
  442. foreach($statesArray as $array => $value)
  443. print("STATES[$array]=$value <br>");
  444. }
  445.  
  446. ?>
  447. Program 10-------------------------------------------------------------------------------------------------------------------------
  448. <?php
  449.  
  450. $servername = "localhost";
  451.  
  452. $username = "root";
  453.  
  454. $password= "root";
  455.  
  456. $dbname= "weblab";
  457.  
  458. $a=[];
  459. //Create connection
  460.  
  461. // Opens a new connection to the MySQL server
  462.  
  463.  
  464.  
  465. $conn = mysqli_connect($servername, $username, $password, $dbname);
  466.  
  467.  
  468.  
  469. // Check connection and return an error description from the lastconnection error, if any
  470.  
  471. if ($conn->connect_error)
  472.  
  473.  
  474.  
  475. die("Connection failed: " . $conn->connect_error);
  476.  
  477. else
  478.  
  479. echo "sucessful connection<br />\n";
  480.  
  481.  
  482. $sql = "SELECT * FROM student";
  483.  
  484. echo "hi";
  485.  
  486. // performs a query against the database
  487.  
  488.  
  489. $result = $conn->query($sql);
  490.  
  491.  
  492. echo "<br>";
  493. echo "<center> BEFORE SORTING </center>";
  494.  
  495. echo "<table border='2'>";
  496. echo "<tr>";
  497.  
  498. echo "<th>USN</th><th>NAME</th><th>Address</th></tr>";
  499.  
  500. if ($result->num_rows> 0)
  501.  
  502. {
  503. // output data of each row and fetches a result row as an associative array
  504.  
  505. while($row = $result->fetch_assoc())
  506.  
  507. {
  508.  
  509. echo "<tr>";
  510.  
  511. echo "<td>".$row["usn"]."</td>";
  512.  
  513. echo "<td>".$row["name"]."</td>";
  514.  
  515. echo "<td>".$row["address"]."</td>";
  516.  
  517. echo "</tr>";
  518.  
  519. array_push($a,$row["usn"]);
  520.  
  521. }
  522.  
  523. }
  524.  
  525.  
  526. else
  527.  
  528.  
  529. echo "Table is mpty";
  530.  
  531. echo "</table>";
  532.  
  533.  
  534.  
  535. $n=count($a);
  536.  
  537. $b=$a;
  538.  
  539. for ( $i = 0 ; $i< ($n - 1) ; $i++ )
  540.  
  541. {
  542.  
  543. $pos= $i;
  544.  
  545. for ( $j = $i + 1 ; $j < $n ;$j++ )
  546.  
  547. {
  548.  
  549. if ( $a[$pos] > $a[$j] )
  550.  
  551. $pos= $j;
  552.  
  553. }
  554.  
  555.  
  556. if ( $pos!= $i )
  557.  
  558. {
  559.  
  560. $temp=$a[$i];
  561.  
  562. $a[$i] = $a[$pos];
  563.  
  564. $a[$pos] = $temp;
  565.  
  566. }
  567.  
  568. }
  569.  
  570. $result = $conn->query($sql);
  571.  
  572. if ($result->num_rows> 0)// output data of each row
  573.  
  574. {
  575.  
  576. while($row = $result->fetch_assoc())
  577.  
  578. {
  579.  
  580. for($i=0;$i<$n;$i++)
  581.  
  582. {
  583.  
  584. if($row["usn"]==$a[$i])
  585.  
  586. {
  587.  
  588. $c[$i]=$row["name"];
  589.  
  590. $d[$i]=$row["address"];
  591.  
  592. }
  593.  
  594. }
  595.  
  596. }
  597.  
  598. }
  599.  
  600. echo "<br>";
  601.  
  602. echo "<center> AFTER SORTING<center>";
  603.  
  604. echo "<table border='2'>";
  605.  
  606. echo "<tr>";
  607.  
  608. echo"<th>USN</th><th>NAME</th><th>Address</th></tr>";
  609.  
  610.  
  611. for($i=0;$i<$n;$i++)
  612.  
  613. {
  614.  
  615. echo "<tr>";
  616.  
  617. echo "<td>". $a[$i]."</td>";
  618.  
  619. echo "<td>". $c[$i]."</td>";
  620.  
  621. echo "<td>". $d[$i]."</td></tr>";
  622.  
  623. }
  624.  
  625. echo "</table>";
  626.  
  627. $conn->close();
  628.  
  629.  
  630. ?>
Add Comment
Please, Sign In to add comment