Group Contact

Today, i am going to write first post for mySql. mySql has many functions to make programmer’s life easy.

When i was doing my project, i have to display some data by grouping with one field.

Example :

Suppose you have Student table with skill.

srno student skill
1 Jaydip PHP
2 Sanjay PHP
3 Jaydip Android
4 Pratik PHP
5 Sanjay CI
6 Pratik Magento

 

Now you want to display like student with all skills in one row.

srno student allskill
1 Jaydip PHP,Android
2 Sanjay PHP,CI
3 Pratik PHP,Magento

 

To get result like this, GROUP_CONTACT is there in mySql.

GROUP_CONTACT Query :

SELECT srno,student,GROUP_CONTACT(skill) AS allskill FROM student_skill GROUP BY user;

 

Search with one more value

Today, I will show you how to display different value on list and how to search from another value.

When i was doing my project, i have to display list item with different search value. So i have customized bootstrap for this.

To do this use attribute “renderField”.

Example :

$('#typeahead').typeahead({

     renderField: "display_text",

});

you have to add this renderField into data object.

Data object example :

item = {}

item.display_text = "searchvalue1 searchvalue2";

item.value= "displayvalue";

When you type searchvalue1  or searchvalue2 or displayvalue. This item will show in all three search. and it will display displayvalue only.

 

#codewithgeek #codewithjaydip

Li color based on condition

Bootstrap Typeahead is used for autosuggestion list based on type text in input.

I have customized this js and added more function, so that you can easily used this for multi purpose.

Li color based on condition

To change color of list element based on search content. I have added colour attribute for this.

$('#typeahead').typeahead({
   colour: "colourCondition"
});

Here coloutCondition is javascript function

function colourCondition(item, i) {
       if (item.type == 3) {
            i.addClass("color-brown"
       }
}

Download bootstrap-typeahead.js from github

PHP for beginners – Chapter 3

Here we are going to learn third step towards PHP. PHP for beginners – Chapter 3.

How to run a sample “hello world” code. Is there any server or compiler required for that?

I hope you have read PHP for beginners – Chapter 1 and PHP for beginners – Chapter 2 before reading this Chapter. In this chapter you will know how to run your code.

Once you have written you code. It is very important to run code. To run code, we need to start Apache server. You have to install Wamp or Xampp server for this.

I will explain you this in Xampp server.

Open Xampp Control Panel. You will see as per following image.

Xampp Control Panel

Click on Start button in row of Apache Module. It will start Apache Server. To check it is working proper or not open your browser and type http://localhost

If it will run successful then it will display following page.

This is indicating that you have successfully install xampp control panel. Now you are ready to play with PHP.

 

 

PHP for beginners – Chapter 2

Here we are going to learn second step towards PHP. PHP for beginners – Chapter 2.

How to write a code? Means you need to know about editor in which you can make a code.

To write code in PHP, if you have good editor then you can write code in more speed and efficiently.

There are some free and paid editor available to write code.

Free Editor :

  1. Notepad++
  2. Net Beans
  3. Brackets

Paid Editor :

  1. Dreamweaver
  2. PHPStrom

Here i listed only editors which i know. There are others also available.

I have used above all. I prefer Net Beans which is free. PHPStrom is also very good. But it is paid editor.

Just click on editor you want use and download it from there.

Click here to Start with PHP for beginners – Chapter 3

PHP for beginners – Chapter 1

Here we are going to learn first step towards PHP. PHP for beginners – Chapter 1.

How many software are required?

To make a code in PHP we need to compile or run code. PHP is server side scripting language. So you need apache server to run written  PHP code.

There are two famous software who provide server for PHP.

  1. Wamp Server
  2. Xampp Server

You can download wamp server from here. 

You can download xampp server from here. 

You need mySql server also to communicate with Database.

You will find this in built with these two software.

Just follow simple steps and you are done with software installation to run PHP code.

Click here to Start with PHP for beginners – Chapter 2

 

How to find duration between two time

Hello Geeks,

Today we will learn how to get duration between given two time. Some time we want to get duration of selected time period. So, how to it with help of javascript.

Here I will explain you how to do it with javascript.

Example,
We will take example of two time. Suppose we want to get sleeping duration of any person. Suppose person is sleeping at 10:00 PM and wake up at 05:00 AM. So sleeping hours is 7 and minute is 0.

Now we will do it with code.


<script type="text/javascript">
    function returnNumber(v) { 
       v = parseInt(v);
       if (isNaN(v)) {
           return 0;
       } else {
           return v; 
       }
    }

    valuestart = "10:45 PM";
    valuestop = "07:30 AM";
    amPM1Arr = valuestart.split(" ");
    amPM2Arr = valuestop.split(" ");
    amPM1 = amPM1Arr[1];
    amPM2 = amPM2Arr[1];
    timiningArr2 = amPM2Arr[0].split(":");
    timiningArr1 = amPM1Arr[0].split(":");
    if (amPM1 == amPM2) {
        timiningArr2 = amPM2Arr[0].split(":");
        timiningArr1 = amPM1Arr[0].split(":");
        totalHour = returnNumber(timiningArr2[0]) - returnNumber(timiningArr1[0]);
        totalMin = returnNumber(timiningArr2[1]) - returnNumber(timiningArr1[1]);
        if (totalHour < 0 ) {
            totalHour = totalMin= 0;
        } else {
            if(totalMin < 0) { 
                totalHour--; 
                totalMin = 60 +totalMin; 
            } 
       } 
    } else { 
        totalHour = 0; 
        totalMin = 0; 
        if (amPM1 == "PM" && amPM2 == "AM") { 
            totalHour += returnNumber(timiningArr2[0]); 
            timiningArr1[0] = returnNumber(timiningArr1[0]); 
            totalHour += (11 - timiningArr1[0]); 
            totalMin = 60 - returnNumber(timiningArr1[1]); 
            totalMin += returnNumber(timiningArr2[1]); 
        } else if (amPM2 == "PM") { 
            totalHour = returnNumber(timiningArr2[0]); 
            totalHour += (11 - timiningArr1[0]); 
            totalMin = 60 - returnNumber(timiningArr1[1]); 
            totalMin += returnNumber(timiningArr2[1]); 
        } 
        if (totalMin > 60 ) {
            extraH = totalMin%60;
            totalHour = totalHour + extraH;
            totalMin = totalMin - (extraH*60);
        } else if (totalMin == 60) {
            totalHour++;
            totalMin=0;
        }
    }
    console.log(totalHour+":"+totalMin);
</script>