Here is the Drupal 8 Query to get category info
here category name “color_cat”
$vid = ‘color_cat’;
$parent_tid = 0;//parent id
$depth = 2; //depth upto which level you want
$load_entities = FALSE;
$cat_data= \Drupal::entityTypeManager()->getStorage(‘taxonomy_term’)->loadTree($vid,
$parent_tid, $depth, $load_entities);
$variables[‘color_cat’] = $cat_data;
add below code inside your .theme file
in .twig file you have use below twig code to display category name
{% for key1, value in color_cat %}{{ color_cat[key1]['name'] }}
{% endfor %}host is not allowed to connect to this mysql server
one of the most conman error when connecting to MySQL server is “host is not allowed to connect to this MySQL server” this because of the user don’t have right privileges to connect to this MySQL server follow below steps to connection issue in MySQL
if you have full permission in MySQL
Open Mysq-> phpmyadmin
Go to User accounts section
Create a new user and give all the privilege as shown in the below image
if you have cpanel info
Go to MySQL® Databases section
Scroll down to Add New User section
After Scroll down to Add User To Database section
Select table and user and Add User To Database
Click all ALL PRIVILEGES and Make Changes
Select all data from MySQL where date between two given dates
Here is the simple MySQL query to fetch data between given date range
See MySQL query
$f_date=$_REQUEST['f_date']; $t_date=$_REQUEST['t_date']; "SELECT * FROM sales WHERE sales_invoice_date between '".date('Y-m-d',strtotime($f_date))."' and '".date('Y-m-d',strtotime($t_date))."' "To Fetch all the sales data in the given date
"SELECT * FROM sales WHERE sales_invoice_date='".date('Y-m-d',strtotime($f_date))."'"To fetch Today’s Sales
SELECT * FROM sales WHERE STR_TO_DATE(sales_invoice_date , '%d-%m-%Y') = CURDATE()Full Text Search In MySQL ,a better way for MySQL Text search
One of the most common issue with MySQL is searching for a matching string from a huge database,suppose we need to search for ‘MySQL Tutorial’ it will only search the occurrence of ‘MySQL Tutorial’ neither ‘MySQL’ or ‘Tutorial’ also in MySQL compared to INT value search Char/Text is time consuming to solve this issue, we have Full Text Search .Full Text Search is a technique used by search engine to find the results in a database.we can use Full Text search in search Query.First you must create a full-text index on the table before you run full-text queries on a table.
Creating a full-text index inside a Table
ALTER TABLE TABLE NAME ADD FULLTEXT (FIELD1, FIELD2,FIELD3, etc) Example ALTER TABLE wptt_posts ADD FULLTEXT (`post_title`, `post_content`)![]()
Now we created Full Text Index in wptt_posts table,next we will discuss how to use Full Text Search in MySQL
MySQL Query Using Full Text SearchSELECT * FROM TABLE NAME WHERE MATCH (FILED1FILED2,FILED3) AGAINST ('SEARCH WORD' IN NATURAL LANGUAGE MODE) Example SELECT * FROM wptt_posts WHERE MATCH (post_title,post_content) AGAINST ('Mysql Tutorials' IN NATURAL LANGUAGE MODE)![]()
We can use the match case based on the Score
SELECT MATCH (post_title,post_content) AGAINST ('Mysql Tutorials') as score, post_title FROM wptt_posts WHERE MATCH (post_title,post_content) AGAINST ('Mysql Tutorials' IN NATURAL LANGUAGE MODE)Where the score value represent the occurrence of search term in the filed
We can skip words (exclude words) from the result
For e.g “-Tutorials” means the search result should not contain Tutorials
SELECT * FROM wptt_posts WHERE MATCH (post_title,post_content) AGAINST ('+Mysql -Tutorials' IN BOOLEAN MODE)