Web Development - Page 3 of 7 -

Check perfect number using PHP Code

This is interview question .How to check a entered number is a perfect number of not

Output of the code :

I have taken 13 so it will give this output

:-

Your enterded number is not a Perfect Number

How to print a traigle using PHP Code :- We can print stars traingle using for loop .

Now if you run this code in your browser then it will show this output


* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
* * * * * * * * 
* * * * * * * * * 
* * * * * * * * * * 

Now we will see another example

Now if you will run this code in your browser Output :-

* * * * * * * * * * * * * * * 
* * * * * * * * * * * * * * 
* * * * * * * * * * * * * 
* * * * * * * * * * * * 
* * * * * * * * * * * 
* * * * * * * * * * 
* * * * * * * * * 
* * * * * * * * 
* * * * * * * 
* * * * * * 
* * * * * 
* * * * 
* * * 
* * 

Now another patter for star traingle

If you run this program in your broswer Output :

See more PHP Tutorials

Hide & Show paragraph using jquery

We can show and hide paragraph using hide() show() method

$(“.btnHide”).click(function(){ This line of code will hide paragraph & .btnHide is class name of button . If you use id then your code would be like this $(#btnHide).click(function(){ becuase we use (#) this sign for id.

Now we will see another example just copy the code and run into browser

Output of code

$(“p.normal”).show();
$(“p.fast”).show(“fast”);
$(“p.slow”).show(“slow”);
$(“p.vfast”).show(110);
$(“p.vslow”).show(5000);
});

110 and 5000 are timing in miliseconds so 5000 miliseconds means 5 seconds it means last paragraph will take 5 seconds to hide and 5 seconds to show .

See more tutorials

Drop down in php

Insert form data into database using php

Dropdown list in php

To display drowdown list in php we can use for-each loop . We have some data in our array so we cant display it using php array logic

Output of code :



strtolower    function is used to convert string to lower case . Array is a specail variable used to store more than one data

See more php tutorials : Insert Data into Database using PHP-PDO Method

PHP Logical programs for interview

PSD to html/wordpress conversion

CRUD operation in php-pdo

Insert form data into database using php-mysqli

It is very easy to insert data into database using php and i will you mysqli. I have used post method for data insertion. It is upto you & you can use post or get method for form handling .

Your database table will look like this :- Only two coulmn needed user_name & user_comment .

user_name user_comment
maheshI am mahesh a web developer

Output of above code : Demo Form

Write your name & post your comment :





If you hit comment button then it will show you this message

” Your data inserted into database successfully “

Now i am giving you second form example in which first i will add data into database then i will fetch it from database

Output of code :

Write your name & post your comment :





Now if you add some data in this form and hit Comment button then it will show all data from database

How to use Loops in PHP

There are three types of loop in php : While loop , do while loop , for & for-each loop

While Loop :- loops through a block of code unitl the specified condition become true

Now below is first example of while loop

Output of code would be this :

4
8
12
16
20
24
28
32
36
40
44
48
52
56
60

Now i will teach you how to write for loop code . The for loop is used when you know in advance how many times the your script will run

for (init counter; test counter; increment counter)

{
  Your code logic ;
}

Output of codw would be this

No is: 5 
No is: 6 
No is: 7 
No is: 8 
No is: 9 
No is: 10 
No is: 11 
No is: 12 
No is: 13 
No is: 14 
No is: 15 
No is: 16 
No is: 17 
No is: 18 
No is: 19 
No is: 20 

The loop output starts from 5 and end to 20 becuase x = 5 and till x = < 20

Now we will see for-each loop . This loop is only for array when you use array that time for- each loop can be used

foreach ($array as $value)

{
Your code logic;
}

Now we will see one example in for – each loop

Output of code would be this

Check these tutorials in php

PHP – PDO Insert data into database using OOP Concept

I am using PDO – OOP concept for inserting data into database . If you are new to pdo then please learn basics of pdo . I have used simple OOP concept only class for connection and function for executing pdo query .

This is table in db & coulmn names are : id , name , age & email

idnameageemail
1bobby39[email protected]
2harsh33[email protected]
3nimesj23[email protected]
4aftab12[email protected]

Please make same table as i have made for you dont change column names otherwise you will get errors & if you want different names then you have to change all coulmn names in php code .

Now if you will run this code in your browser then your output will be this

idnameageemail
1bobby39[email protected]
2harsh33[email protected]
3nimesj23[email protected]
4aftab12[email protected]
5Robert Venda31[email protected]

Please dont use mysql now start using mysqli or pdo

PHP logical programs for Interviews

1-How to get leap year in PHP using HTML form

Leap year has 366 days .It adds extra day in calendar (Feb 29) , 2016 was a leap year and 2020 will be a leap year . Now we will see how to get leap year using php code .

2 – How to get cube root of any number using PHP Code

This way you can get cube root of any number

PHP basic programs for interviews

PHP Program for factorial using HTML Form and this is formula for factorial : –

n n!
1 – 1 1 1
2 – 2 × 1 = 2 × 1! = 2
3 – 3 × 2 × 1 = 3 × 2! = 6
4 – 4 × 3 × 2 × 1 = 4 × 3! = 24
5 – 5 × 4 × 3 × 2 × 1 = 5 × 4! = 120

This is uptop 5 now see up to 25 and Formula will be the same for all digit

n n!
0- 1
1 -1
2 -2
3- 6
4- 24
5- 120
6- 720
7- 5,040
8- 40,320
9- 362,880
10 3,628,800
11 39,916,800
12 479,001,600
13 6,227,020,800
14 87,178,291,200
15 1,307,674,368,000
16 -20,922,789,888,000
17 -355,687,428,096,000
18 -6,402,373,705,728,000
19 -121,645,100,408,832,000
20 – 2,432,902,008,176,640,000
21 – 51,090,942,171,709,440,000
22 – 1124,000,727,777,607,680,000
23 – 25,852,016,738,884,976,640,000
24- 620,448,401,733,239,439,360,000
25 – 15,511,210,043,330,985,984,000,000

Now i will show you code for the factorial series

How to get PRIME NUMBER using PHP Code

2 is a prime number , 3 is also a prime number and 4 composite ..

Where clause in php-mysql

Where cluase is used to only fetch those records that full fill a specified records

This is our where clause query with select statement

SELECT * FROM users WHERE name =”rahul” . Now this query will give all
record of rahul

Now this is our table in database and the database is test and the table name is users .

idnameageemail
1ronit Singh34[email protected]
2ankit33[email protected]
3rahul11[email protected]
4sharad31[email protected]
5raja31[email protected]

Now i will write php code to show this table on browser with help of where clause query . As you can see there is one raja in the table so i will try to fetch it by using php-mysql .Now below is our php code

This where clause query using php code and below is our output

idnameageemail
5raja31
[email protected]