Comment on my HTML, CSS, JavaScript, and PHP code?
When you are designing your website, there are many instances that require you to comment out code in your website. Commenting code is good for diagnosing website problems, hiding code instead of deleting the code, placing notes in a file to explain what was done, and many more reasons. This article will explain the basics of commenting code in your website files.
HTML Comments
HTML comments are specifically designed to comment out code when you are in an HTML-coded document. Below is the syntax for HTML comments.
HTML comment
Example of an HTML comment
An Example of a usage of this is shown in the following code.
CSS, JavaScript, and PHP Comments
CSS comments are done in the CSS .css stylesheet or in the Internal Style sheet. JavaScript comments can be placed inside HTML documents or in a .js file where JavaScript is run. PHP code will be in .php files between <?php
and ?>
code. The following code shows the syntax for commenting out CSS, JavaScript, and PHP code.
Single Line comment
Multiple Line comment
Example of PHP comment
An Example of a usage of this is shown in the following code. Below is showing PHP code; however, you use the same process to comment on JavaScript and CSS.
MySQL supports three comment styles:
- From a
'-- '
to the end of the line. The double dash-comment style requires at least whitespace or control character (space, tab, newline, etc) after the second dash.SELECT * FROM users; -- This is a comment
Note that standard SQL does not require whitespace after the second dash. MySQL uses whitespace to avoid the problems with some SQL construct such as:
SELECT 10--1;
The statement returns 11. If MySQL didn’t use the whitespace, it would return 10 instead.
- From a
'#'
to the end of the line.SELECT lastName, firstName FROM employees WHERE reportsTo = 1002; # get subordinates of Diane
- C-style comment
/**/
can span multiple lines. You use this comment style to document a block of SQL code./* Get sales rep employees that reports to Anthony */ SELECT lastName, firstName FROM employees WHERE reportsTo = 1143 AND jobTitle = 'Sales Rep';
Notice that MySQL does not support nested comments.
Executable comments
MySQL provides executable comments to support portability between different databases. These comments allow you to embed SQL code that will execute only in MySQL but not other databases.
The following illustrates the executable comment syntax:
/*! MySQL-specific code */
Code language: SQL (Structured Query Language) (sql)
For example, the following statement uses an executable comment:
SELECT 1 /*! +1 */
Code language: SQL (Structured Query Language) (sql)
The statement returns 2 instead of 1. However, it will return 1 if you execute it in other database systems.
If you want to execute a comment from a specific version of MySQL, you use the following syntax:
/*!##### MySQL-specific code */
Code language: SQL (Structured Query Language) (sql)
The string ‘#####’ represents the minimum version of MySQL that can execute the comment. The first # is the major version e.g., 5 or 8. The second 2 numbers (##) are the minor version. And the last 2 is the patch level.
For example, the following comment is only executable in MySQL 5.1.10 or later:
CREATE TABLE t1 (
k INT AUTO_INCREMENT,
KEY (k)
) /*!50110 KEY_BLOCK_SIZE=1024; */
Code language: SQL (Structured Query Language) (sql)
In this tutorial, you have learned how to use MySQL comments to document the SQL code in MySQL.
0 Comments
CAN FEEDBACK
Emoji