Welcome to Eazy Program !

Here, you can learn simple but very useful tips
that you want when you are working on coding and programming. And also you are able to know about
the things related to blogging. Further, you have the
ability to use the projects that I have done in your work.
About Me
The main purpose of this blog is to give extra knowledge to make your code, project, and career beautiful.

Saturday, March 27, 2021

Hello Programmers, We are going to talk about a very important topic. This is based on an input tag in HTML, the type of the tag is "date". Yes, it is. As with the other input tag types in the HTML, the "date " type also behaves in the same manner but, there are some little differences in this case. Will see it...


Just like the other input tags, we can style this type=" date" tag using CSS and JavaScript. Also if we include an input tag with type=" date" to the source file, id displays the values to the user in dd/mm/yyyy format... No, it's wrong!. It depends on the browser. The browser decides how it appears on the interface.

Browser like Chrome, Firefox, Opera, and Internet Explora use the dd/mm/yyyy format. But some browsers use different formats in the interface of the file. These are some examples:

  • In Chrome:

  • In Firefox:

  • In Internet Explora:

  • In Opera:


But, there is something that always the same in every browser. That is every browser outputs the selected date by the user in the format of yyyy-mm-dd, with global $_POST variable using PHP.

Below I have included a function to handle the date using PHP. 


You can download that file and use it on your project using PHP method; <?php require_once("path/time.php") ?>. To use this, you simply paste the time.php file inside your project folder and, use this PHP method line to include the date function that I have included here on your source file. Here path means the location. If you have pasted the time.php file inside another folder in your project folder you should add that filename as the path. Otherwise, if you have pasted the time.php sile directly inside the project folder, no need to add the path, just use it like this: <?php require_once("time.php") ?>. you can directly copy and paste the code of the function onto your source file.

By using this function, you can take a date input from the user and, check whether the date that the user-selected is a previous date or not. And also this function outputs the number of days difference with the current date.

These are the most important basic things of the input types of the date in HTML you must know. Use these tips and make your project or code pleasant with EAZY PROGRAM. If you have any issues or if this post was helpful for you, please leave a comment. Also, share this with your friends on social media and follow us to know these kinds of useful tips, and subscribe to our newsletter to get a notification as soon as we publish a new post. See you soon. Until then,  Happy coding... Stay safe...!


Categories: ,

Thursday, March 11, 2021

 

When creating a website, an application, or maybe software, you need to create a database to store the records. There are so many Database Management Systems(DBMS) applications, for example, Php MyAdmin, MySql Workbench. Whatever application you use, you must insert the records taken from the application, with a unique record id.

Yes, it is a simple thing which is creating a unique record id for every record. In Php MyAdmin, we can create a field with name as Id, index as primary, type as Int and, by ticking on auto-increment we can create a record Id field with the integer data type. Also, it is an auto-increment field(No need to add the values to that field, when inserting the records. Values are automatically added by auto-incrementing one by one). It gives unique numbers as IDs to every record in the table. But it is a little bit not suitable when you are working on a project or when developing an application or software.

Therefore we can create an Id with other characters that related to a specific table in the database. It is very easy to identify the table by looking out the record Id, and also it gives a rather pleasant look to your work. For example, we can create a Users table with an Id field which values in the format of USR_001, USR_002, ..., USR_023, etc, also an Admins table with an Id field which values in the form of ADM_001, ADM_097 likewise.

Let's see how we can do this, and I'm going to tell you to step by step as before. Here I use Php MyAdmin to tell you how to do this task but I use the SQL commands, not the interface of the Php MyAdmin. Hence you can use those codes in your preferred database management system application or in command prompt also.


  • Step 01: As the first step, here I create a table in the database as the users, And I create a user_id field to insert values in the form of USR_###. I use the data type of user_id field as varchar because we use characters in the values.
CREATE TABLE users(user_id VARCHAR(7) NOT NULL PRIMARY KEY DEFAULT '0', first_name VARCHAR(30), last_name VARCHAR(30));

Now I have created a table with no records.


  • Step 02: Create another table to create a trigger to format the values in the user_id field of the user table. This table I named as users_seq. Here I use the data type of id field as an integer. Because we use this table to make our user_id field in the users table with characters.
CREATE TABLE users_seq(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY);



  • Step 03: Now create a trigger on the users table to connect both tables and to do our task. We need a trigger to insert the values first to the users_seq table and then insert the values to the users table to the field of user_id in the form of USR_###
DELIMITER $$
CREATE TRIGGER tg_users_insert
BEFORE INSERT ON users
FOR EACH ROW
BEGIN
  INSERT INTO users_seq VALUES (NULL);
  SET NEW.user_id = CONCAT('USR_', LPAD(LAST_INSERT_ID(), 3, '0'));
END$$
DELIMITER ;

In Php MyAdmin, you can see the created triggers of a table in the trigger tab as shown below. Go to the table, and then go to the trigger tab.

  • Step 04: Now simply insert few records to users table and see the values of the user_id field.
INSERT INTO users(first_name, last_name) VALUES ('Jhon', 'Doe');
INSERT INTO users(first_name, last_name) VALUES ('Kevin', 'Mogan');

Here you go... All the values of the user_id field are in the form of USR_###.


Likewise, you can create a field for the Id field, or maybe another field which is values contains the characters also. You can create your own form of the values. You only need to do is, changing the trigger values as you wish. Use these tips and make your project or code pleasant with EAZY PROGRAM. If you have any issues or if this post was helpful for you, please leave a comment. Also, share this with your friends on social media and follow us to know these kinds of useful tips. See you soon. Stay safe...!

Categories: