Friday, 13 January 2023

Full Screen Search Box HTML

 HTML CODE

<div id="myOverlay" class="overlay">

  <span class="closebtn" onclick="closeSearch()" title="Close Overlay">x</span>
  <div class="overlay-content">
    <form action="action_page.php">
      <input type="text" placeholder="Search.." name="search">
      <button type="submit"><i class="fa fa-search"></i></button>
    </form>
  </div>
</div>

CSS CODE

/* The overlay effect with black background */
.overlay {
  height: 100%;
  width: 100%;
  display: none;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: rgb(0,0,0);
  background-color: rgba(0,0,0, 0.9); /* Black with a little bit see-through */
}

/* The content */
.overlay-content {
  position: relative;
  top: 46%;
  width: 80%;
  text-align: center;
  margin-top: 30px;
  margin: auto;
}

/* Close button */
.overlay .closebtn {
  position: absolute;
  top: 20px;
  right: 45px;
  font-size: 60px;
  cursor: pointer;
  color: white;
}

.overlay .closebtn:hover {
  color: #ccc;
}

/* Style the search field */
.overlay input[type=text] {
  padding: 15px;
  font-size: 17px;
  border: none;
  float: left;
  width: 80%;
  background: white;
}

.overlay input[type=text]:hover {
  background: #f1f1f1;
}

/* Style the submit button */
.overlay button {
  float: left;
  width: 20%;
  padding: 15px;
  background: #ddd;
  font-size: 17px;
  border: none;
  cursor: pointer;
}

.overlay button:hover {
  background: #bbb;
}
 JS CODE

// Open the full screen search box
function openSearch() {
  document.getElementById("myOverlay").style.display "block";
}

// Close the full screen search box
function closeSearch() {
  document.getElementById("myOverlay").style.display = "none";
}
Share:

Thursday, 12 January 2023

Basic PHP Syntax

 A PHP script is executed on the server, and the plain HTML result is sent back to the browser.


Basic PHP Syntax

A PHP script can be placed anywhere in the document.

A PHP script starts with <?php and ends with ?>:

<?php

// PHP code goes here

?>

The default file extension for PHP files is ".php".

A PHP file normally contains HTML tags, and some PHP scripting code.

Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page

<!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>


</body>
</html>

In PHP, keywords (e.g. ifelsewhileecho, etc.), classes, functions, and user-defined functions are not case-sensitive.

In the example below, all three echo statements below are equal and legal

<!DOCTYPE html>
<html>
<body>

<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>


</body>
</html>

Note: However; all variable names are case-sensitive!

Look at the example below; only the first statement will display the value of the $color variable! This is because $color$COLOR, and $coLOR are treated as three different variables:

<!DOCTYPE html>
<html>
<body>

<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>


</body>
</html>


Share:

PHP Installation

 

What Do I Need?

To start using PHP, you can:

  • Find a web host with PHP and MySQL support
  • Install a web server on your own PC, and then install PHP and MySQL

Use a Web Host With PHP Support

If your server has activated support for PHP you do not need to do anything.

Just create some .php files, place them in your web directory, and the server will automatically parse them for you.

You do not need to compile anything or install any extra tools.

Because PHP is free, most web hosts offer PHP support.


Set Up PHP on Your Own PC

However, if your server does not support PHP, you must:

  • install a web server
  • install PHP
  • install a database, such as MySQL

The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php

Share:

Python MongoDB Insert Document

  document in MongoDB is the same as a record in SQL databases.

To insert a record, or document as it is called in MongoDB, into a collection, we use the insert_one() method.

The first parameter of the insert_one() method is a dictionary containing the name(s) and value(s) of each field in the document you want to insert.

Insert a record in the "customers" collection

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]

mydict = { "name""John""address""Highway 37" }

x = mycol.insert_one(mydict)

The insert_one() method returns a InsertOneResult object, which has a property, inserted_id, that holds the id of the inserted document.

mydict = { "name""Peter""address""Lowstreet 27" }

x = mycol.insert_one(mydict)

print(x.inserted_id)

If you do not specify an _id field, then MongoDB will add one for you and assign a unique id for each document.

In the example above no _id field was specified, so MongoDB assigned a unique _id for the record (document).

To insert multiple documents into a collection in MongoDB, we use the insert_many() method.

The first parameter of the insert_many() method is a list containing dictionaries with the data you want to insert:

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]

mylist = [
  { "name""Amy""address""Apple st 652"},
  "name""Hannah""address""Mountain 21"},
  { "name""Michael""address""Valley 345"},
  { "name""Sandy""address""Ocean blvd 2"},
  { "name""Betty""address""Green Grass 1"},
  "name""Richard""address""Sky st 331"},
  { "name""Susan""address""One way 98"},
  { "name""Vicky""address""Yellow Garden 2"},
  { "name""Ben""address""Park Lane 38"},
  "name""William""address""Central st 954"},
  { "name""Chuck""address""Main Road 989"},
  { "name""Viola""address""Sideway 1633"}
]

x = mycol.insert_many(mylist)

#print list of the _id values of the inserted documents:
print(x.inserted_ids)

The insert_many() method returns a InsertManyResult object, which has a property, inserted_ids, that holds the ids of the inserted documents.

If you do not want MongoDB to assign unique ids for you document, you can specify the _id field when you insert the document(s).

Remember that the values has to be unique. Two documents cannot have the same _id.

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]

mylist = [
  { "_id"1"name""John""address""Highway 37"},
  "_id"2"name""Peter""address""Lowstreet 27"},
  { "_id"3"name""Amy""address""Apple st 652"},
  { "_id"4"name""Hannah""address""Mountain 21"},
  { "_id"5"name""Michael""address""Valley 345"},
  { "_id"6"name""Sandy""address""Ocean blvd 2"},
  { "_id"7"name""Betty""address""Green Grass 1"},
  { "_id"8"name""Richard""address""Sky st 331"},
  { "_id"9"name""Susan""address""One way 98"},
  { "_id"10"name""Vicky""address""Yellow Garden 2"},
  { "_id"11"name""Ben""address""Park Lane 38"},
  { "_id"12"name""William""address""Central st 954"},
  { "_id"13"name""Chuck""address""Main Road 989"},
  "_id"14"name""Viola""address""Sideway 1633"}
]

x = mycol.insert_many(mylist)

#print list of the _id values of the inserted documents:
print(x.inserted_ids)

Share:

Python MongoDB Create Collection

 To create a collection in MongoDB, use database object and specify the name of the collection you want to create.

MongoDB will create the collection if it does not exist.

Create a collection called "customers":

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]

mycol = mydb["customers"]

Important: In MongoDB, a collection is not created until it gets content!

Remember: In MongoDB, a collection is not created until it gets content, so if this is your first time creating a collection, you should complete the next chapter (create document) before you check if the collection exists!

You can check if a collection exist in a database by listing all collections:

Return a list of all collections in your database:

print(mydb.list_collection_names())

Or you can check a specific collection by name:

Check if the "customers" collection exists:

collist = mydb.list_collection_names()
if "customers" in collist:
  print("The collection exists.")


Share:

Python MongoDB Create Database

 To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct ip address and the name of the database you want to create.

MongoDB will create the database if it does not exist, and make a connection to it.

You can check if a database exist by listing all databases in you system:

Return a list of your system's databases

import pymongo

myclient = pymongo.MongoClient("mongodb://localhost:27017/")

mydb = myclient["mydatabase"]

print(myclient.list_database_names())

Or you can check a specific database by name

Check if "mydatabase" exists

dblist = myclient.list_database_names()
if "mydatabase" in dblist:
  print("The database exists.")


Share: