How to use Grocery crud and Tank auth together?

Step 1). Download and extract all the files from archives of both grocery crud and tank auth in Codeigniter.

Step 2) Import their schema and install them according to the instruction given on their respective sites and test whether they are working individually.

Step 3) Change address of your default route controller at routes.php to
$route['default_controller'] = "examples"; // grocery crud controller

Step 4)  In examples controller construct paste following line
$this->load->library('tank_auth'); // we need to load tank auth library in example controller
Step 5) In index function of examples controller, write code to check whether user is logged in or not:
public function index()
if (!$this->tank_auth->is_logged_in()) {
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array(),'data' => $data));
Step 6) Now in example views create a log out link:
Hi, ! You are logged in now.

How to use OR and AND conditions in a single query?

Today when I was coding for one of my projects, I required to use OR and AND queries together. And with having good experience in Mysql and PHP Programming, I thought I can do it easily. But when I did use the query, It was not working as expected. After analyzing my query, I got to know that it was checking AND and OR conditions separately and giving result even when AND condition is false because I forgot to use Bracket with OR conditions.

My Requirement: Select employee_id of all employers with common name 'John' , age>24 or city London

Name should be John
Age or City condition (One of them should be true)

Problematic Query: 
$sql = "Select employee_id from employers where employers.employee_name = '$name' AND employee_age > '$age' OR employee_city = '$city'";

It gives me result set with names other than John

Solution Query:
$sql = "Select employee_id from employers where employers.employee_name = '$name' AND (employee_age > '$age' OR employee_city = '$city')";

Updating all values using Single Query

Table which needs modification: TableA
Column whose value we need to change: ColA
Present Value: 2
New Value : 3

Query will be

SET ColA = '3' 
WHERE ColA = '2' 

How to improve page load speed of your php website?

1. Use include at the place of include_once for including files

2.Remove Blank Spaces from your php code.You can use this function:

function removeBlankLines($string)
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);

3. Use , (comma) at the place of . (period) and single quote(') at the place of double quote(") wherever possible in echo statements.
For ex.
echo "my name is". $this->name."and your is".$this->your_name;
echo 'my name is',$this->name,'and your is',$this->your_name;

4. Provide width and height of image tags. For eg width="10" height="10"

5. Use CDN for external Javascript files.

6. If you are using jquery or any other popular js technologies, then use google library service

7.Compress your css with css compressor.

8. Use minified version of javascript libraries, if not available then create one for yourself using sites like javascript compressor.

9.If possible write css files on page itself i.e inline, if file is too large then write css for visible content first on webpage and import css file in footer.

10. Import Javascript files in footer and not in header.

11. Load Javascript and other content Asynchronously or with the help of Ajax.

12. For image which are not above the fold, you can use lazyload javascipt to delay their loading.Read more about Lazy Load Plugin.

13. Compress your images using Yahoo Smush it

14. Use Gzip for compressing webpage.
Use this code before doctype to enable gzip compression on linux servers
 if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();

15. Remove errors and warning from your code.

16. Use only required variables, if possible use values instead of variable.
For ex.
for($i=1;$i<$j;$i++) {   } // do something
for($i=1;$i<10 do="" font="" i="" nbsp="" something="">

17. Use microtime function of php to measure time taken by php to execute any specific function. For eg. if I want to measure time taken by first_function, I can measure it with the following code:
$time_start = microtime(true);
// Call your function
$time_end = microtime(true);
$time = $time_end - $time_start;

echo "Total time to execute first function is $time seconds\n";

18. Use HTTP Caching : For PHP Website you can use header function or mod_expires

19. Avoid using SQL queries in loops(While or For), instead of that use array inside the loop and use implode function to append that array in SQL query.

20. Optimize CSS by using common declarations: 
h1 { padding-top: 10px; }
p { padding-top: 10px; }
h1, p { padding-top: 10px; }

21. Use complex query instead of multiple queries to reduce number of requests.
Select * from products where pid=1;
Select * from text where pid=1; 
Select * from products,text where =

22. You can use mysql procedure's at the place of php function. It will enhance your website security and performance.

IA previous year exam paper and solution

IA Paper Answers and Questions

Q1.If L stands for +, M stands for -, N stands for x, P stands for / then 15N 10 L 30 P 6 M 8 =
(1) 145 (2)147 (3)146 (4) 148
Step1) Change the equation into correct format which is
15 x 10 + 30 / 6 - 8
Step2) Use BODMAS that is Division first ,than multiplication , than addition and afterwards subtraction.

Step3) 15 x 10 + 5 - 8 (Division)

Step4) 150 + 5 - 8 ( Multiplication)

Step5) 155 - 8 (Addition)

Step6 147

That is (2)

Q2. If 20-10 means 2; 8 / 4 means 32; 6 x2 means 8, then 100 -10 x 4 /6 equals
(1) 32 (2) 34 (3)36 (4) 35

Step1) Try to figure out what the above equations signifies.
That is what 20-10 = 2 signifies, what mathematical operator we should use between these two number so we get the value 2? Only division(/) operator which gives us 2 at RHS. So - => / ( minus sign implies division).
Similarly / => x and x => + respectively.

Step2) 100 -10 x 4/6 changes into 100 / 10 + 4 x 6

Step3) 10 +4 x 6

Step4) 10 + 24

Step5) 34

That is (2)

Q3. Five persons A,B,C,D and E are sitting in a row. Who is sitting in the middle if:  (i) B is between E and C, (ii) B is to the right of C (iii) D is between A and E
(1) D (2) B (3) E (4) A

To find out middle person, we need to write each person position on paper according to the information given to us.

Step1).        E      B       C ( B is between E  and C)

Step2).       C     B     E ( B is right of C and B is between E and C)

Step3).     C B E D A  ( B is right of C , B is between E and C and  D is between A and E)

So middle term is E.

So Answer is (3) E.

Q4. What is the number of squares in the following figure?
(1)18 (2) 10 (3) 9 (4) 14

We will try to solve this problem by canceling least possible option for eg. By putting numbers inside the square, we can make out one conclusion that squares can't be less than 9.
Step1. (1 2 4 5) makes one more square so total squares become 9 + 1= 10 so (3) option is incorrect 
Step2.( Similarly 4 5 7 8) makes one square and total becomes 11 , so we can cancel (2) nd option too.
Step3. Now there is only two options left, by assumption I can say that there are only 14 squares possible , but if you want to count you can.
So Answer is 14 that is (4) 

Q5. A is three year older to B and 3 years younger to C, B and D are twins. How many years older is C to D?
(1) 2 (2) 3 (3) 6 (4) 12

Write equations from the information given above:
 A = 3 +  B --> Eq 1
 C = A + 3 --> Eq 2
 B = D
 Find equation between C and D

Step 1) A = 3 + D ( we know B = D , so we replace B with D)
Step 2) C = 3 + D + 3 ( Replace  A with Eq 1)
Step 3) C = 6 + D
So, we can conclude that C is 6 years older than D that is (3).

Q6. Find the number which when added to itself 13 times gives 112
(1) 7 (2) 8 (3) 9 (4) 11

Let x be the number , which is added to itself 13 times that is 13x.
x + 13x = 112
x = 112/14 = 8

That is option (2).

Q7.(A)Rahul at present is 25 years younger to his mother.
 (B) Rahul brother, who was born in 1964, is 35 years younger to his mother.
In which year year was Rahul Born?
(1) (A) alone is sufficient while (B) alone is not sufficient
(2) (B) alone is sufficient while (A) alone is not sufficient
(3) Either (A) or (B) is sufficient
(4) Both (A) and (B) are sufficient

From A we know that Rahul is 25 years younger to his mother but with this information we can't deduce Rahul's age.
From B we can find out the born year of Rahul's mother but still this information can't be used to find Rahul's age, for that we need first statement.
So Answer is (4) Both (A) and (B) are sufficient.

Q8. (A) One fourth of the weight of each pole is 5 Kg.
(B)The total weight of three poles is 20 Kg more than the total weight of two poles.
What will be the total weight of 10 poles, each of same weight ?
(1) (A) alone is sufficient while (B) alone is not sufficient
(2) (B) alone is sufficient while (A) alone is not sufficient
(3) Either (A) or (B) is sufficient
(4) Both (A) and (B) are sufficient

Solution. Lets weight of one pole is x and according to A 1/4 * x = 5 so x = 20 Kg.
and from B  3x = 20 + 2x which means x = 20 ,so total weight become 200 Kg.

So answer is (3) Either (A) or (B) is sufficient

Q9. (A) A company sold 8000 units of product each costing Rs.25
(B). This company has no other product line
How much was the total sale of the company?
(1) (A) alone is sufficient while (B) alone is not sufficient
(2) (B) alone is sufficient while (A) alone is not sufficient
(3) Either (A) or (B) is sufficient
(4) Both (A) and (B) are sufficient

(1) (A) alone is sufficient while (B) alone is not sufficient

Q10. What is the number of triangles in the above figure?

(1)8 (2) 10 (3) 12 (4) 14

Q11. What number should come next in the series: 2,1,(1/2),(1,4),________
(1)1/3 (2) 1/8 (3) 2/8 (4) 1/16

Q12. What number should come next in the series 7,10,8,11,9,12_______
(1) 7 (2) 12 (3) 10 (4) 13

Their is two series in this question

Q13. Statement: NO women teacher can play. some women teachers are athletes. Conclusions:
(A) Male athletes can play
(B) Some athletes can play
(1) Only conclusion (A) Follows
(2) Only conclusion (B) Follows
(3) Either conclusion(A) or (B) Follows
(4) Neither (A) nor (B) Follows

Q14. Marathon: race :: hibernation:______

(1) Winter (2) Bear (3) Dream (4) Sleep

Marathon is a type of race and hibernation is a type of sleep

Q15. 3G is:

(1) a generation of standards for mobile phones
(2) name of a scam
(3) a generation of standards for landline phones
(4) none of the above

Q16. Latest processor from intel is:
(1) core 2 duo (2) dual core (3) core i5 (4) pentium

Reason: core i5 and i7 are the latest processors from Intel.

Q17. Full form of UPS is:
(1). Uninterfered power supply 
(2)  Uninterrupted power supply
(3)  Uniform power source
(4)  Uniform power supply

Q18. RAM in present day computers is available in size of 
(1) MB (2) GB (3) TB (4) KB

Q19. Full form of GUI is:
(1) Graphics use interaction 
(2) Graphical user interface
(3) Graph use interface
(4) None of the above

Q20. Which one of the following is magnetic devices?
(1) Tapes (2) Hard disks (3) Both (1) and (2) (4) None of the above

Q21. The Rajasthan canal takes water from:
(1) Ravi (2) Satlaj (3) Ghaghara (4) Yamuna

Q22. Keoladeo National Park is situated in:
(1) Alwar (2) Bharatpur (3) Ghana ( 4) Ranthambore

Q23. Which of the following states is largest in area?
(1) Madhya Pradesh, (2) Uttar Pradesh (3) Rajasthan (4) Maharashtra

Q24. International women's day is celebrated on:
(1) May 27 (2) January 9 (3) April 7 (4) March 8
Q25. Jai Jawan Jai Kissan slogan was given by:
(1) Indira Gandhi (2) Lal Bahadur Shastri (3) Mahatma Gandhi (4) Jawahar Lal Nehru

Q26. Insulin controls metabolism of 
(1) Sugar (2) Fats (3) Proteins (4) Salts

Q27. The capital of Chhattisgarh is:
(1) Jamshedpur (2) Indore (3) Raipur (4) Bhopal 

Q28. Baghdad is the capital of which country?
(1) Afghanistan (2) Kuwait (3) Iraq (4) Saudi Arabia

Q29. What is the sum total of all angles of a right angled triangle ?
(1) 90 degrees (2) 185 degrees (3) 180 degrees (4) 45 degrees

Sol.Sum total of angles of any triangle is 180 degree 

Q30. In which country is Wimbledon tennis tournament held?
(1) USA (2) Australia (3) France (4) England 

Q31. Which of the following devices can be used to directly read image printed text ?
(1) OCR (2) OMR (3) MICR (4) All of the above

Sol. This question can be easily answered if you know the full form of OCR which is Optical Character Recognition

Q32. Which of the following are the two main components of the CPU ?

(1) Control Unit and registers (2) Registers and main memory (3) Control Unit and ALU (4) ALU and Bus

Q33. The advantage of Component Object Model is it's _______and_______
(1) Compact size, speed readability (3) Compact Size and Speed (3) Readability, speed (4) Low cost, readability

 Q34. If a computer on the network shares resources for others to use, is is called ______
(1) Server (2) Client (3) Mainframe (4) None of these

Q35. The output quality of a printer is measured by
(1) Dot per inch (2) Dot per sq. inch (3) Dots printed per unit time (4) All of above

Q36. Convert: (1111001) base 2 -> ( ) base 10
(1) 31 base 10 (2) 121 base 10 (3) 27 base 10 (4) 29 base 10

Sol.   1x64 + 1x 32 + 1 x 16 +  1 x 8 + 0 x 4+0 x 2 + 1 x 1 = 121