Skip to content

Instantly share code, notes, and snippets.

@nisargjhaveri
Created February 20, 2016 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisargjhaveri/dbe4c7aa95a9f9f54938 to your computer and use it in GitHub Desktop.
Save nisargjhaveri/dbe4c7aa95a9f9f54938 to your computer and use it in GitHub Desktop.
Webdev Workshop - Day 2 - Codes we used today while explaining
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<form action="lang.php" method="get">
<input value="default" name="lang" type="text">
<input value="Go" type="submit">
</form>
</body>
</html>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$lang = $_GET['lang'];
$types = [
'c' => "Procedural",
'c++' => 'Hybrid',
'java' => 'Object Oriented',
'js' => 'Hybrid',
'php' => 'Hybrid'
];
$type = $types[$lang];
echo "$lang is a $type language";
<?php
$db_config = [
'host' => 'localhost',
'username' => 'root',
'password' => '',
'db_name' => 'test'
];
$db_link = mysqli_connect(
$db_config['host'],
$db_config['username'],
$db_config['password'],
$db_config['db_name']
);
$result = mysqli_query($db_link, "SELECT * from student");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table border="1">
<tr>
<th>#</th>
<th>Name</th>
<th>Roll no</th>
</tr>
<?php
$i = 1;
while ($row = mysqli_fetch_assoc($result)) {
$name = $row['name'];
$roll_no = $row['roll_no'];
echo "
<tr>
<td>$i</td>
<td>$name</td>
<td>$roll_no</td>
</tr>";
$i++;
}
?>
</table>
</body>
</html>

CRUD (Create, Retrieve, Update, Delete)

Create - Insert query

INSERT INTO table (col1, col2) VALUES ('value1', 'value2');

Retrieve - Select query

SELECT col1, col2 FROM table WHERE somecol='someval';

Update - Update query

UPDATE table SET col1 = 'value1' WHERE somecol = 'someval';

Delete - Delete query

DELETE FROM table WHERE somecol = 'someval'
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//code
//statement ;
//
$name = [5, 5, 'web'];
//$name = array();
$name[0] = 6;
$name[2] = 9;
$name['hi'] = 9;
//foreach ($name as &$val){
// echo "$val ";
// }
foreach ($name as $value) {
// echo "Value: $value<br />\n";
}
// 0 -> 6
// 1 -> 5
// 2 -> 9
// hi -> 9
// var_dump($name);
$name = "This is a string ";
// echo 12/5;
// echo $name, " hello";
// This is how you declare a function
function hello() {
echo "Hello";
}
echo "<br><hr>";
function sum($number1, $number2=100) {
$sum = $number1 + $number2;
return $sum;
}
$my_sum = sum(45, 10);
//echo $my_sum;
//echo $var1 + $var2;
//echo "<br>";
//echo $var1 . $var2;
//exit();
$var1 = 1000;
$var2 = '1000';
if ($var1 === $var2) {
//echo "equal";
}
else {
//echo "not equal";
}
$some_variable = "This is a string";
function my_function() {
global $some_variable;
echo $some_variable;
}
echo "Hello<br>";
echo "world\n";
echo "nice\n";
echo "string\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment