29 june 2012

tty Command

tty is a Unix command that prints to standard output the name of the terminal connected to standard input. The name of the program comes from teletypewriter, abbreviated “TTY”.

Execute shell script in php

The following command worked :
shell_exec(‘sh shell_file.sh’);

Enabling a cgi directory for each user

<Directory /home/*/public_html/cgi-bin/>
Options ExecCGI
SetHandler cgi-script
</Directory>

Then, presuming that UserDir is set to public_html, a cgi program example.cgi could be loaded from that directory as:

http://example.com/~rbowen/cgi-bin/example.cgi

.htaccess files provide a way to make configuration changes on a per-directory basis.

28 June 2012

Apache Module mod_status

The Status module allows a server administrator to find out how well their server is performing. A HTML page is presented that gives the current server statistics in an easily readable form.

To enable status reports only for browsers from the domain. Add this code to your httpd.conf configuration file.

<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from abc.com
</Location>

You can now access server statistics by using a Web browser to access the page http://your.server.name/server-status.

APACHE WEB PAGE LOGIN AUTHENTICATION

Apache authentication can be configured to require web site visitors to login with a user id and password. This is different than adding a login form on a web page and creating your own authentication.

Create the directory you want to password protect.
Create a file /home/domain/public_html/dirname/.htaccess in that director that looks something like this:

 AuthName "Add your login message here."
 AuthType Basic
 AuthUserFile /home/domain/public_html/membersonly/.htpasswd
 AuthGroupFile /dev/null
 require user name-of-user

In this case the “name-of-user” is the login name you wish to use for accessing the web

Create the password file /home/domain/public_html/membersonly/.htpasswd using the program htpasswd:
htpasswd -c .htpasswd name-of-user

File privileges: chmod ug+rw .htpasswd

26 June 2012

Config File:
A text file containing directives that control how the Web server should operate. Config files live in the conf subdirectory under the ServerRoot.

Directive:
A one-line text command in a config file which instructs the server in some aspect of its operation. Directive names are not case-sensitive, but the arguments that follow them on the line usually are.
Examples: User, DirectoryIndex.

DocumentRoot:
The top of the directory tree where your Web content actually lives.

Internet Media Type:
An attribute of a document that describes the format of the content. The IMT is split into a major and minor portion, separated by a slash. Some examples are “text/plain” for normal unformated text or prose; “text/html” for text that contains HTML tags; “image/gif” denotes a binary image in GIF format.

MIME Type:
MIME is an acronym for Multipurpose Internet Mail Extensions, a set of standards defining howmail of various types and contents can be exchanged. Since the MIME system defined a very flexible way of assigning attributes to message bodies.

Overrides:
The types of settings that can be changed by directives in .htaccess files. If the FileInfo keyword is in the list of allowed overrides.

Scope:
A bounded portion of your server’s URI space or filesystem. Scopes are nestable, and directive effects typically are inherited from higher-level scopes. The narrowest applicable scope ultimately defines the attributes of Web resources within it.

ServerRoot:
The top of the directory tree where the server application itself, and all the configuration files, lives.

Virtual Hosting:
A means of making a single system appear to be multiple ones.

25 June 2012

All constant values change to variable.

Constant values
$parent_qid = 5;
$sid=68316;
$gid=3;
$y=4;

Change to variables

$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))
{
$cc=mysql_query("SELECT `qid` FROM $quesTable WHERE `question` = 'Major Area' AND sid='$bb[sid]'");
while($dd=mysql_fetch_array($cc))
{
$sid=$bb['sid'];
$parent_qid = $dd['qid'];
}
$ee=mysql_query("SELECT `gid` FROM $group WHERE description = 'It is related to post applied.' AND sid='$bb[sid]'");
while($ff=mysql_fetch_array($ee))
{
$gid=$ff['gid'];
$gg=mysql_query("SELECT `qid` FROM $quesTable WHERE question = 'Name of the post' AND sid='$bb[sid]'");
while($hh=mysql_fetch_array($gg))
{
$y=$hh['qid'];
}
$ii=mysql_query("SELECT qid FROM $quesTable WHERE sid='$bb[sid]' AND gid='$ff[gid]'");
}
while($jj=mysql_fetch_array($ii))
{
}}

To make it flexible I use variable name for tables and store real values in another file which contain

<?php
$db_host="localhost";
$db_username="root";
$db_password=" ";
$database=" ";
$mainTable="lime2_survey_68316";
$quesTable="lime2_questions";
$languagesetting= "lime2_surveys_languagesettings";
$group= "lime2_groups";
?>
To Eliminate null values
I used submitdate !=’NULL’ //wrong way
It is solved by using
submitdate != ' '

Remove Redundancy
This query returns one row if two rows have same email id and with current submitted date.
First I use DISTINCT function.Then I use GROUP BY clause.

SELECT DISTINCT email FROM `lime2_survey_68316` ORDER BY submitdate DESC // wrong way
SELECT * FROM $mainTable WHERE $m='Y' AND $z='Y' ANd submitdate != '' GROUP BY email Order by submitdate DESC //write way

I want to pull out duplicate records in a MySQL Database. This can be done with:

SELECT address, count(id) as cnt FROM list
GROUP BY address HAVING cnt > 1

Rajgarh Trip

It was 3’0 clock in the morning when my alarm woke me up and My friend Vigas and Sukhdeep have called me again and again so that I track with time.The best thing is that I was going to wear new dress which I got last night from boutique with very difficulty . After sometime I was ready with new shoes and dress, Then I kick my Brother to woke him up and asked him to drop me at college. I reached last in all my friends at college. I was excited and looking beautiful. Their was dark night when we started our journey to Rajgarh near 4:30. We went Pinjore Garden for breakfast and I was very haapy by seeing poha made by madam. After collecting memories we moved to Rajgarh. when we came closer to rajgarh, warm winds turns to cold breeze. When we saw the camping area river was flowing side by, all were excited to go in it and we took various snaps over there and get chance of mountain trekking. It is the best experience I ever had. Mango is my favourite fruit and I happy to saw its availablity. While we were eating mangoes we splashed water, sung songs. I felt like that I seen movie. After enjoying Valley, We moved for baru sahib gurudwara. There we saw small childrens singing shabads and making langar. When enjoyed the nature of Himalyas we decided to go back home and it tooks 7 hours. After reaching ludhiana took dinner in jimidar’s dhaba. My dad waited upto 2:30. I reached home with cheerful smile.

21 June 2012

My problem is that the loop only display SQ001 to SQ009

$SQ_No = SQ00;
for ( $a = 1; $a <= 11; $a++)
{ }

This problem is solved by using this code.

for ( $a = 1; $a <= 11; $a++)
{ 
$SQ_No = "SQ" . sprintf('%03d', $a);
}

Now it print upto SQ001 to SQ011.

Explode function

$pieces=explode("X",$m);

To count rows

if ($num_results > 0){
$count= $num_results;}

Display only one and latest value
Order by id DESC limit 1

To insert Page Break

h3 {page-break-before: always;}

To produce pdf form web page.

use ctrl-p

20 June 2012

VIM Usage
Vim is an editor to create or edit a text file.
There are two modes in vim. One is the command mode and another is the insert mode.
In the command mode, user can move around the file.
In the insert mode, user can insert text.

Changing mode from one to another
From command mode to insert mode type a/A/i/I/o/O ( see details below)
From insert mode to command mode type Esc (escape key)

Some useful commands for VIM
Text Entry Commands (Used to start text entry)
a Append text following current cursor position
A Append text to the end of current line
i Insert text before the current cursor position
I Insert text at the beginning of the cursor line
o Open up a new line following the current line and add text there
O Open up a new line in front of the current line and add text there

The following commands are used only in the commands mode.
Cursor Movement Commands
h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line

Exit Commands
:wq Write file to disk and quit the editor
:q! Quit (no warning)
:q Quit (a warning is printed if a modified file has not been saved)

Editing the Existing File
Step 1 type vim filename (edit the existing file named filename)
Step 2 move around the file using h/j/k/l key or any appropriate command

h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line
(ex. 10G goes to line 10)

Step 3 edit required text (replace or delete or insert)
Step 4 hit Esc key (exit from insert mode if you insert or replace text)
Step 5 type :wq

Collation in mysql database
Collation in MySQL Database is a set of rules used in comparisons.Because many people use MySQL with data to be stored in languages other than English, they need to select the rules of comparisons which in turn depends on the character set used for storing that data.In other words, Collation refers to the character set used to store data in text fields and is necessary to provide support for all of the many written languages of the world. MySQL 4.1 added the ability to override the default system collation at the database, table, and field level.
The default collation in MySQL, latin1_swedish_ci, works fine for English because English contains no special characters such as accents. phpMyAdmin allows you to edit the collations of your database, tables, and fields if you desire to support languages other than or in addition to English.

19 June 2012

Retrieve all information with in single id. Query used to do this.

$result = mysql_query("SELECT id,submitdate,datestamp,startdate,68316X4X34,68316X4X23,68316X4X7 FROM lime_survey_68316 ORDER BY id");
while($row = mysql_fetch_array($result))
{
echo $row['id']."<br>";
echo "First Name:".$row['68316X4X23']."<br>";
echo "Last Name:".$row['68316X4X7']."<br>";
echo "Email id: ".$row['68316X4X34']."<br>";
echo "Submit Date:".$row['submitdate']."<br>";
echo "Datestamp".$row['datestamp']."<br>";
echo "Startdate".$row['startdate']."<br>";
 for ( $rraii = 1; $rraii <= 11; $rraii++)
 { 
 $m=$sid."X".$gid."X".$parent_qid.$title.$rraii;
 $u=mysql_query("SELECT $m FROM lime_survey_68316 WHERE $m='Y' AND id='$row[id]'");
 while($v= mysql_fetch_array($u))
 {
 if($v[$m]='Y'){
 echo "Department:".$m."<br>";
 }
 for ($my=1; $my<=3; $my++)
 {
 $z=$sid."X".$gid."X".$y.$title.$my;
 $b=mysql_query("SELECT $z FROM lime_survey_68316 WHERE $z='Y' AND id='$row[id]'");
 while($f= mysql_fetch_array($b))
 {
 if($f[$z]='Y'){
 echo "job:".$z."<br>";
 }
}}}}}

Output

5
First Name:Rajdeep
Last Name:Kaur
Email id: rpanesarz@gmail.com
Submit Date:2012-06-11 15:05:02
Datestamp2012-06-11 15:05:02
Startdate2012-06-11 13:40:29
Department:68316X3X5SQ002
job:68316X3X4SQ001
6
First Name:baljit
Last Name:singh
Email id: rpanesar91@yahoo.com
Submit Date:2012-06-12 10:38:10
Datestamp2012-06-12 10:38:10
Startdate2012-06-12 10:33:15
Department:68316X3X5SQ002
job:68316X3X4SQ001
job:68316X3X4SQ002
job:68316X3X4SQ003
Department:68316X3X5SQ009
job:68316X3X4SQ001
job:68316X3X4SQ002
job:68316X3X4SQ003

18 June 2012

I do some changes in it now it did not come double time by id.

1.Column name
68316X3X5SQ002 that is department
is made by this code.

$parent_qid = 5;
$sid=68316;
$gid=3;
$title="SQ00";
$y=4;
for ( $a = 1; $a <= 11; $a++)
{ 
 $m=$sid."X".$gid."X".$parent_qid.$title.$a;
 }

2.Column name
68316X3X4SQ001 that is job is made by this code.

for ($my=1; $my<=3; $my++)
{
$z=$sid."X".$gid."X".$y.$title.$my;
}

3.Query which help to get single id and single department and multiple jobs they applied for.

$result = mysql_query("SELECT id,68316X4X23,68316X4X7,$m FROM lime_survey_68316 WHERE $m='Y' ORDER BY id");
 while($row = mysql_fetch_array($result))
 {
 echo $row['id']."<br>";
 echo $row['68316X4X23']."<br>";
 echo $row['68316X4X7']."<br>";
 echo $m."<br>";
 for ($my=1; $my<=3; $my++)
 {
 $z=$sid."X".$gid."X".$y.$title.$my;
$b=mysql_query("SELECT $z FROM lime_survey_68316 WHERE $z='Y' AND id='$row[id]'");
 while($f= mysql_fetch_array($b))
 {
 if($f[$z]='Y'){
 echo $z."<br>";
 }}}}

Output

5
Rajdeep
Kaur
68316X3X5SQ002
68316X3X4SQ001
6
baljit
singh
68316X3X5SQ002 //department 1
68316X3X4SQ001 //apply for multiple jobs
68316X3X4SQ002
68316X3X4SQ003
6
baljit
singh
68316X3X5SQ009 // department 2 
68316X3X4SQ001
68316X3X4SQ002
68316X3X4SQ003