concat multiple rows into a single text string with separator – MySql

group_concat() – Mysql

This function allows you to concat multiple rows in to a single string based on value.

This is the query for that -

select group_concat(tag separator ‘,’) as output from design_tag  group by design_id

Real world problem and Scenario:

If you have 2 tables:  design and design_tag,  look at structure of the tables.

 

 

 

 

 

 

 

 

 

 
design_tag table structure:

 

If you want to store the “design_tag.tag” in to “design.tags” with comma separator based on the relation of design.id=design_tag.design_id then use this query.

update design set tags=(select group_concat(tag separator ‘,’) from design_tag where id=design_id group by design_id)

This will produce the final output like this:

 

 

 

 

 

 

 

 

 

 

 

 

Learn more about group_concat here:
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html

What is wordpress?

WordPress was first released on May 27, 2003, by Matt Mullenweg. WordPress is a weblog software. developed using PHP.
Today’s WordPress is really a “content management system” (CMS), which means that it can be used to run full-sized, social media-rich business websites.
Wordpress has many features:

1) WordPress designs are based on “Themes”.
2) WordPress software allows anyone to create and edit new web pages and blog “posts” using only a web browser.
3) WordPress allows you to place and re-place widgets without editing HTML.
4) It provides themes option & admin can switch theme by one click

WordPress has won following awards:

WordPress won a Packt Open Source CMS Award.[Year 2007]
WordPress won the best Open Source CMS Award.[Year 2009]
WordPress won the Hall of Fame CMS category in the 2010 Open Source Awards. [Year 2010]
WordPress won the Open Source Web App of the Year Award at The Critters. [Year 2011]

Enable / disable javascript on browser

Firefox
Go to the “Tools” menu. 

Select “Options”.

Select the “Content” icon.

Check the checkbox corresponding to “Enable Javascript”.

Click “OK” to save changes.

Internet Explorer
Select “Internet Options” from the “Tools” menu. 

Click on the “Privacy” tab.

Scroll down bar to “Medium” under “Settings”.

Click “OK”.

Netscape Navigator
Click “Edit” from the menu bar. 

Select the item “Preferences”.

Click “Advanced”.

Click box for “Enable JavaScript”.

Click OK to save the changes.

Chrome
Click on “Settings” => “Options” 

Click on “Under the hood” at left side bar

Choose “Privacy”

Choose “content settings”

You will see “Javascript” & allow, disable options there.

array in java script

Javascript Array:

Variables can hold one value at a time. If you want to store some more values of same type then  you need a special varibale theat can be store more than one value. The special type of variable is called as an array. Array is a variable which can hold more than one value, at a time with index.

Lets see with an example:

If you want to show total of 2 variables the you will use variable with name “total” BUT if you want to store name of multiple users then? there is a problem to create multiple variables for dynamic names if you fetched from database.. Use array at that time.

Example:

Programmer: Prashant, Deep, Dear, Dearphp

You will store these all names in a single variable with an indexes like:

var programmer = new Array(); // Array declaration

programmer[0] = ‘Prashant’;
programmer[1] = ‘Deep’;
programmer[2] = ‘Dear’;
programmer[3] = ‘Dearphp’;

Our aim is achieved by declaring one variable named “programmer” & placed values in it with indexes.

how to print that values or how to access from array?
use for loop

for(index in programmer) {
alert(programmer[index]);
}
This loop will alert 4 times & each time iterate through 0 to 3 index & alert a value for that index as “Prashant”…”Dearphp”
OR
alert(programmer[1]); // alert “Deep”

Hope you will understand.

How to run javascript

There are many scenarios to run javascript.

If you have a javascript code and saved in notepad with an .htm extension. When you go to file then open and type file name, it just opens up a it as an address in the address bar.

If its a Firefox then you are good to go with that file But if you try to open or run that file in browser then IE will give you pop-up at the top of document.

we will go with an example:

lets see with an example, If you have a javascript code:

<script type=”text/javascript”>
alert(‘This is javascript alert’);
</script>

Saved in file with extension .html or .htm

Run in FF.

 

 

 
You will see an alert box if you run that file in FF.

If you try to run same file in IE you will get an pop-up & ask for permission to run that file or not.

If the file is just a javascript file you have to save it with a .js file extension. JavaScript does not run on its own. It must be part of a webpage.

Next… How you would call it from an HTML page?

Put the tag in <head><script src=”<?=SITE_PATH?>test.js” type=”text/javascript”></script>  </head>

Put the js code in test.js and place path in src=”" atribute of <script> tag.

[Note: If you run the webpage using http(s) protocol then IE will not produce that pop-up]

Thats it..!