30 July 2012

Lime survey contains three types of columns
68321X7X7
68321X7X7SQ001
68321X7X7SQ001_SQ007
This function returns all type of columns

function Concatenate($constSid,$varInfo,$table) //concatenatination of gid,qid with survey id.
 { 
 foreach($varInfo as $realInfo) //$VarInfo contains array of gid,qid, rreturn one by one.
 {
 if(($realInfo['type'] == ";") || ($realInfo['type'] == ":"))
 { 
 $colQuery=mysql_query("SELECT DISTINCT title,gid,parent_qid FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' ");
 while($colInfo = mysql_fetch_array($colQuery)) 
 { 
 $conValue['title']=$colInfo['title'];
 $conValue['gid']=$colInfo['gid'];
 $conValue['parent_qid']=$colInfo['parent_qid'];
 $abc=mysql_query("SELECT title FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' group by title having count(*) > 1 ");
 while($def = mysql_fetch_array($abc))
 {
$meanValue[]=$constSid."X".$conValue['gid']."X".$conValue['parent_qid'].$conValue['title']."_".$def['title'];
 } 
 }
 }
 elseif(($realInfo['type'] == "M") || ($realInfo['type'] == "Q"))
 { 
 $colQuery=mysql_query("SELECT title,gid,parent_qid FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' ");
 while($colInfo = mysql_fetch_array($colQuery)) 
 {
 $meanValue[]=$constSid."X".$colInfo['gid']."X".$colInfo['parent_qid'].$colInfo['title'];
}
}
  elseif(($realInfo['type'] != "M") || ($realInfo['type'] != "Q") || ($realInfo['type'] != ":") || ($realInfo['type'] != ";"))
 {
 $ghi=mysql_query("SELECT title,gid,qid FROM $table where qid='$realInfo[qid]' and gid='$realInfo[gid]' ");
 while($jkl = mysql_fetch_array($ghi)) 
 {
 $meanValue[]=$constSid."X".$jkl['gid']."X".$jkl['qid'];
}
}
 }
 return $meanValue; ///return array of column name of questions
 }

29 July 2012

The problem is solved by using one single word that is distinct.
The columns which are repeating now it is not repeat because second sql query is with distinct value

function Concatenate($constSid,$varInfo,$table) //concatenatination of gid,qid with survey id.
 {
 foreach($varInfo as $realInfo) //$VarInfo contains array of gid,qid, rreturn one by one.
 {
 if(($realInfo['type'] == ";") || ($realInfo['type'] == ":"))
 {
 $colQuery=mysql_query("SELECT DISTINCT title,gid,parent_qid FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' ");
 while($colInfo = mysql_fetch_array($colQuery)) 
 { 
 $conValue['title']=$colInfo['title'];
 $conValue['gid']=$colInfo['gid'];
 $conValue['parent_qid']=$colInfo['parent_qid'];
 $abc=mysql_query("SELECT title FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' group by title having count(*) > 1 ");
 while($def = mysql_fetch_array($abc))
 {
 $meanValue[]=$conValue['parent_qid'].$conValue['title']."_".$def['title'];
 } 
 }
 }
}
 return $meanValue; ///return array of column name of questions
 }

Dreamful Night

Hello Everyone

I want to share my night dream.
Friday night when I shutdown my laptop, with one problem. Then full night I was dreaming of different solutions related to the problem. When I wake up, brushing ,bathing, my mind kept thinking for the solutions.
When I go for Training and apply the solution to that problem, the problem
was solved:)

But not in efficient manner:(

Somebody said “Bad programming is easy. Idiots can learn it in 21 days, even if they are dummies.”

Then again I was looking for the solution to do in efficient manner.
On saturday night, I turn off my laptop with frustation due to no idea to solve it.
Again I saw dream that code characters come out of screen in the form of mosquitoes and biting me that you’ve insulted the code then, I said sorry, I will soon change the code.please leave me.

Then saturday I wrote code in efficient manner and only one mini problem was remaining.
from Yesterday 5’0 clock I was trying to solve it and today problem got solved.

Problem is solved by writing one word DISTINCT in the (SQL query) code. It solves my problem and I am very happy and danced too. Now I comment my code very soon and put it on bitbucket so that everyone view/improve my code.

28 July 2012

Third type of column is 68321X6X7SQ001_SQ007
To get this Firstly I return that values which are repeating.

This code returns title which repeat

select title from find
group by title
having count(*) > 1

and concatenate with all titles which are present.
For Example

function Concatenate($constSid,$varInfo,$table) //concatenatination of gid,qid with survey id.
 {
 foreach($varInfo as $realInfo) //$VarInfo contains array of gid,qid, rreturn one by one.
 {
if(($realInfo['type'] == ";") || ($realInfo['type'] == ":"))
 {
 $colQuery=mysql_query("SELECT title FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' group by title having count(*) > 1 ");
 while($colInfo = mysql_fetch_array($colQuery)) 
 { 
 $conValue[]=$colInfo['title'];
 $abc=mysql_query("SELECT title FROM $table where parent_qid='$realInfo[qid]' and gid='$realInfo[gid]' group by title having count(*) > 1 ");
 while($def = mysql_fetch_array($abc)) 
 }
}
}
 return $conValue; ///return array of column name of questions
 }

But it gives this output

68321X2X3SQ001_SQ001
68321X2X3SQ001_SQ001
68321X2X3SQ002_SQ001
68321X2X3SQ002_SQ001

It returns the double value of which column title repeats.

FAT is only of 24GB not more then exist.

72 dpi good for screen

27 July 2012

This first function return survey id of lime survey. By this we can also return various values because I pass query variables in parameters like $select,$table,$column,$title

function singleColm($select,$table,$column,$title) //return survey id
 {
 $SurQuery=mysql_fetch_array(mysql_query("SELECT $select FROM $table where $column='$title' Order by $select DESC limit 1;"));
 $sid=$SurQuery[$select]; 
 return $sid;
 }

In Process part, I make column names so that answers can fetch with column names.
This function makes two types of columns
1.68321X6X7
2.68321X7X9SQ001

function Concatenate($constSid,$VarInfo) //concatenatination of gid,qid with survey id.
 {
 foreach($VarInfo as $Gid) //$VarInfo contains array of gid,qid, rreturn one by one.
 {
 if($Gid['parent_qid'] == 0) {
 $ConValue[]=$constSid."X".$Gid['gid']."X".$Gid['qid'];
 }
 else{
 $ConValue[]=$constSid."X".$Gid['gid']."X".$Gid['parent_qid'].$Gid['title'];
 }
 }
 return $ConValue; //return array of column name of questions
 }

One problem in above code that it did not return third type of column.
Third type of column need type of question
Then from input function we can get title.

 function infoQuestion($lastQid,$table) //return gid,qid,parent_qid,title of parameter question
 {
 for($i=1; $i<=$lastQid; $i++)
 {
 $m[]= $i;
 }
 $counterA=0; //used for array purpose
 foreach($m as $quesArray) //retrieve question one by one from array 
 {
 $allInfo=mysql_query("SELECT qid,gid,type FROM $table WHERE qid = '$quesArray'");
 $fetchInfo=mysql_fetch_array($allInfo);
 $mulArray[$counterA][qid]= $fetchInfo['qid']; 
 $mulArray[$counterA][gid]= $fetchInfo['gid']; //return gid of question
 $mulArray[$counterA][type]= $fetchInfo['type']; //return title of question
 $counterA++;
 }
 return $mulArray; 
 //return all question values in array 
 }

Use multiple conditions in if statement

if ((confition1) && (condition2)){
}

26 July 2012

Tmux Session

You can detach it by
press ctrl+b
press d

tmux attach
simple write on terminal tmux attach

In vim
Cut and Paste
press d and press p.

Copy and Paste
In visual mode by press v
press y and select and p where paste.

Commandd used to run command which present in history

!line number

Today I done formatting of code
All constant value change to variable.
Give relevent names to variable.
Use camelCase while giving variable name.
Done with comments in every code of line.

Presenting code after done formatting.
My Mentor is happy with my performance and blessed me by saying that one day you will surely become a Perfect Programmer. And I am damn happy by listening these words from our Mentor like GOD.

Listing your files by size
For listing files by size in ascending order, use:

$ ls -Sl | less

Things Should keep in mind while formatting.
Less spacing between line of code.
Class name formal
File name not include number
Use variable
Learn coding standard

25 June 2012

This function concatenate all the returning values of getQuestion function. To make columns of lime survey Table so that we can retrieve data from main table.

function ConCatenate($ConstSid,$VarInfo)
 {
 foreach($VarInfo as $Gid)
 {
 $ConValue=$ConstSid."X".$Gid['gid']."X".$Gid['qid'];
 }
 return $ConValue;
 }

This function MainInfo get the column names made by above function i.e concatenate function. This function get column name one by one and output the value of that column of lime survey.

function MainInfo($columnName)
 { 
 foreach($columnName as $RealValue)
 {
 $all = mysql_query("SELECT $RealValue FROM lime_survey_68316 WHERE 68316X2X31='dhosdicnio@gmail.com' ");
 while($info = mysql_fetch_array($all))
 {
 $collectInfo[]=$info[$RealValue];
 } 
 }
 return $collectInfo;
 }

Output

Array
(
 [0] => 68316X1X1
 [1] => 68316X1X2
 [2] => 68316X1X3
 [3] => 68316X2X4
 [4] => 68316X2X5
 [5] => 68316X2X6
 [6] => 68316X2X7
 [7] => 68316X2X8
 [8] => 68316X2X9
 [9] => 68316X2X10
 [10] => 68316X2X11
 [11] => 68316X2X12
)
Array
(
 [0] => Programmer
 [1] => Bagga
 [2] => 
 [3] => 1991-10-11
 [4] => Ldhiana
 [5] => A1
 [6] => Indian
 [7] => A2
 [8] => A1
 [9] => A1
 [10] => Y
 [11] => [{ "title":"","comment":"","size":"50.331","name":"logo.png","filename":"fu_yisqdgiee6hzp8b","ext":"png" }]
)

ufw – Uncomplicated Firewall

The default firewall configuration tool for Ubuntu is ufw. Developed to ease iptables firewall configuration, ufw provides a user friendly way to create an IPv4 or IPv6 host-based firewall.

24 June 2012

Count function is used to count the number of rows and return result in numeric value.

function count()
 {
 $Cou_query=mysql_query("SELECT qid FROM lime_questions");
 $num_results = mysql_num_rows($Cou_query);
 if ($num_results > 0){
 return $num_results;
 }
 }

Count function modify to get questions instead to count questions due to requirement change.

function count()
 {
 $ques_query=mysql_query("SELECT question FROM lime_questions");
 while($Qusinfo = mysql_fetch_array($ques_query))
 {
 $QusResult[]=$Qusinfo['question'];
 }
 return $QusResult;
 }

The getQuestion function get the question one by one by using for each loop and return the qid,gid of evry quetion. The array retun value in two dimentional. Because we are using counter and every time counter increment change the array value in one part and in second part real name.

function getQuestion($question)
 {
 $counterA=0;
 foreach($question as $quesArray){
 //echo $quesArray;
 $allInfo=mysql_query("SELECT qid,gid FROM lime_questions WHERE question = '$quesArray'");
 $q1=mysql_fetch_array($allInfo);
 $mul[$counterA][Par_qid] = $q1['qid'];
 $mul[$counterA][Par_gid]= $q1['gid']; 
 $counterA++;
 }
 return $mul;
 }

It works different from above function because we are using here first real value and then counter to print an array of return value.

function getQuestion($question)
 {
 $counterA=0;
 foreach($question as $quesArray){
 $FineQues= str_replace("'" ,"'",$quesArray);
 $allInfo=mysql_query("SELECT qid,gid FROM lime_questions WHERE question = '$FineQues'");
 $q1=mysql_fetch_array($allInfo);
 $mul[qid][$counterA] = $q1['qid'];
 $mul[gid][$counterA]= $q1['gid']; 
 $counterA++;
 }
 return $mul;
 }

Output

Array
(
 [0] => Name of the post
 [1] => Major Area
 [2] => Area of specialisation
 [3] => Applicant's last / family name
 [4] => Father's middle name
 [5] => Date of birth
 [6] => Place of birth
 [7] => Sex
 [8] => Nationality
 [9] => Marital Status
 [10] => Permanent Address
 [11] => Address for Correspondance
 [12] => Contact Number
 [13] => Category
)

 

Array
(
 [0] => 1
 [1] => 1
 [2] => 1
 [3] => 2
 [4] => 2
 [5] => 2
 [6] => 2
 [7] => 2
 [8] => 2
 [9] => 2
 [10] => 2
 [11] => 2
 [12] => 2
 [13] => 2
 [14] => 2
 [15] => 2
 [16] => 2
 [17] => 3
 [18] => 4
 [19] => 2
 [20] => 2
 [21] => 2
 [22] => 2
 [23] => 2
 [24] => 2
 [25] => 2
 [26] => 5
)


23 July 2012

This function returns all data row by row from lime survey where different department is equal to Y and post for the same.

function MainInfo($columnName,$m,$z)
 { 
 foreach($m as $dep){ //m contains all department column in array
 foreach($z as $pos){ //z contain all post column in array
 $yo="SELECT $columnName FROM lime_survey_68316 WHERE $dep='Y' AND $pos='Y' ANd submitdate != '' Order by submitdate DESC "; // column name is selected from lime table where department and post is yes.
 $all = mysql_query($yo);
 while($info = mysql_fetch_array($all))
 {
 $collectInfo[]=$info[$columnName]; // it returns data in an array
 } 
 }
 }
 return $collectInfo;
 }

This function return gid and qid of particular question which has been passed as argument.

function getQuestion($question){
 $allInfo=mysql_query("SELECT qid,gid FROM lime_questions WHERE question = '$question' ");
 while($q1=mysql_fetch_array($allInfo))
 { 
 $mul[Par_qid] = $q1['qid'];
 $mul[Par_gid]= $q1['gid']; 
 }
 return $mul;
 }

Output

Array
(
[0] => 1997-12-03
[1] => 1997-12-17
[2] => 1997-12-03
[3] => 1997-12-03
[4] => 1997-12-09
[5] => 1997-12-11
[6] => 1997-12-09
[7] => 1997-12-11
[8] => 1997-12-09
[9] => 1997-12-03
[10] => 1997-12-17
[11] => 1997-12-09
[12] => 1997-12-03
[13] => 1997-12-03
[14] => 1991-10-11
)


22 July 2012

Today I learn to use class and function in php and how to create object.
This program is used to make lime survey application i.e to retrieve data from database lime survey.

<?php require_once('database.php');
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db,$conn); 
 $aa =mysql_query("SELECT `surveyls_survey_id` as `sid` FROM $languagesetting where `surveyls_title` = 'Application Form for Faculty Position'");
 while($bb = mysql_fetch_array($aa))
 {
 $sid=$bb['sid']; 
 }
 $title="SQ00";
 $nameQQ=mysql_fetch_array(mysql_query("select qid,sid,gid from $quesTable where question='Applicant's first / given name';"));
 $nameColm=$nameQQ['sid']."X".$nameQQ['gid']."X".$nameQQ['qid'];
 $lNameQQ=mysql_fetch_array(mysql_query("select qid,sid,gid from $quesTable where question='Applicant's last / family name';"));
 $lNameColm=$lNameQQ['sid']."X".$lNameQQ['gid']."X".$lNameQQ['qid'];
 $DOBQQ=mysql_fetch_array(mysql_query("select qid,sid,gid from $quesTable where question='Date of birth';"));
 $DOBColm=$DOBQQ['sid']."X".$DOBQQ['gid']."X".$DOBQQ['qid'];
 $phoneQQ=mysql_fetch_array(mysql_query("select qid,sid,gid from $quesTable where question='Contact Number';"));
 $phoneColm=$phoneQQ['sid']."X".$phoneQQ['gid']."X".$phoneQQ['qid']."SQ002";
class Abc
{ 
 /////////function declaration///
 function getMajorArea($sid,$gid,$parent_qid){ 
 for ( $rraii = 1; $rraii <= 13; $rraii++)
 { 
 $SQ_No = "SQ" . sprintf('%03d', $rraii); 
 $m[]=$sid."X".$gid."X".$parent_qid.$SQ_No;
 }
 return $m;
 }
 function getPost($sid,$gid,$title){ 
 for ($my=1; $my<=3; $my++)
 { 
 $z[]=$sid."X".$gid."X".$gid.$title.$my;
 }
 return $z;
 }
 function getQuestion($question){
 $allInfo=mysql_query("SELECT qid FROM lime_questions WHERE question = '$question' ");
 while($q1=mysql_fetch_array($allInfo))
 { 
 $Par_qid = $q1['qid'];
 }
 return $Par_qid;
 }
 function MainInfo($columnName,$m,$z)
 {
 foreach($m as $team[]) { 
 }
 return $team;
 foreach($z as $team1[]) { 
 }
 return $team1;
 $all = mysql_query("SELECT $columnName FROM lime_survey_68316 WHERE $team='Y' AND $team1='Y' ANd submitdate != '' Order by submitdate DESC ");
 while($info = mysql_fetch_array($all))
 {
 $collectInfo=$info[$columnName];
 }
 return $collectInfo;
 }
}
///Create Instance of class
$abc = new Abc();
$MainArray=$abc->MainInfo($DOBColm,$DeptArray,$postArray);
echo $MainArray;
///function cALLING///////
$DeptArray=$abc->getMajorArea($sid,$gid,$parent_qid );
print_r($DeptArray);
echo "<br />";
$postArray=$abc->getPost($sid,$gid,$title );
print_r($postArray);
?>

CLASS

Basic class definitions begin with the keyword class, followed by a class name, followed by a pair of curly braces which enclose the definitions of the properties and methods belonging to the class.

Object OPS

Object-oriented programming (OOP) is a programming paradigm using “objects” – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs.

Function overloading or method overloading is a feature found in various programming languages such as Ada, C++, C#, D and Java, that allows creating several methods with the same name which differ from each other in the type of the input and the output of the function. It is simply defined as the ability of one function to perform different tasks.

For example
main()
{
 cout<<volume(10);
 cout<<volume(2.5,8);
 cout<<volume(100,75,15);
}
 
// volume of a cube
int volume(int s)
{
 return(s*s*s);
}
 
// volume of a cylinder
double volume(double r,int h)
{
 return(3.14*r*r*h);
}
 
// volume of a cuboid
long volume(long l,int b,int h)
{
 return(l*b*h);
}