Android Tutorial , Programming Tutorial, Php Tutorial, Learn Android, HTML Tutorial, Coding , Java Tutorial, GTU Programs, Learning Programming

Tuesday, 30 August 2016

Android Tutorial : Linear Layout Example

In this tutorial , we are learning about linear layout.

Linear Layout is a common and main layout that arranges all components in vertical and horizontal manner. We can set height and width of the layout using layout_width and layout_height property.

Let's see that how this example will work :





Linear Layout in Android






 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:orientation="vertical"
                tools:context=".LinearLayout" >
                
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:paddingLeft="10px"
                            android:paddingTop="20px"
                            android:text="LINEAR LAYOUT EXAMPLE" />
                        
                                    <LinearLayout
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:orientation="horizontal"
                                        android:paddingTop="20px">
                                
                                        <TextView
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"                                            
                                            android:paddingLeft="10px"
                                            android:paddingTop="20px"
                                            android:text="Enter User Name :-" />
                                
                                        <EditText
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:layout_weight="0.50"
                                            android:layout_marginLeft="40px"
                                            android:paddingTop="10px" />


                                    </LinearLayout>
                        
                                    <LinearLayout
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="horizontal"
                                    android:paddingTop="20px"
                                     >
                                    
                                                        <TextView
                                                            android:layout_width="wrap_content"
                                                            android:layout_height="wrap_content"
                                                            android:text="Enter Password :-"
                                                            android:paddingTop="20px"
                                                            android:paddingLeft="10px"/>
                                                        
                                                        <EditText
                                                            android:layout_width="wrap_content"
                                                            android:layout_height="wrap_content"
                                                            android:layout_gravity="center_horizontal"
                                                            android:layout_marginLeft="40px"
                                                            android:layout_weight="0.50"
                                                            android:paddingTop="10px" />
                                 
                                    </LinearLayout>
                                    
                        <Button
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:paddingLeft="20px"
                            android:paddingTop="10px"
                            android:text="BUTTON" />
            
            </LinearLayout>

Wednesday, 10 August 2016

Paging in PHP for Image Gallery

In this tutorial , we are learning that how to create paging in Php for Image Gallery.

Paging means that it is showing query result in multiple pages. It is possible with set limit in SQL Query.

In this example , there are some functions which is used to create paging in php.

  • basename() : It is return the filename from the path.
  • mysql_query() : for sending MySQL Query.
  • mysql_fetch_array() : It is used to fetch result as associative and numeric array.
  • mysql_num_rows() : It is used to fetch result as enumerated array.
  • ceil() : used to round up figure.




File Name : index.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="index2.php"  enctype="multipart/form-data">
 <pre>
  Image Upload<br>
  No   :- <INPUT TYPE='TEXT' NAME='NO' required>
  <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
  Image :- <input name="uploadedfile" type="file" required/> <br>
  <INPUT TYPE="SUBMIT" VALUE="Insert"> <INPUT TYPE="RESET" VALUE="CLEAR">
 </pre>
</FORM>

</BODY>
</HTML>


File Name : index2.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
 $vno=$_POST['NO'];
 $cn=mysql_connect("localhost","root","");

 mysql_select_db("dbtest");

 $fn=basename($_FILES['uploadedfile']['name']);
 $target_path = "./images/";

 $target_path = $target_path.$fn;

 $tfn=$_FILES['uploadedfile']['tmp_name'];

 
  $x=move_uploaded_file($tfn,$target_path);

 if($x)
 {
  echo "<img src='images/".basename($_FILES['uploadedfile']['name'])."'</img> ";
    echo "<br>The file <u>[".basename($_FILES['uploadedfile']['name'])."</u>] has been uploaded<br>";
 }
 else
 {
     echo "There was an error uploading the file";
     die;
 }

 $s1="insert into img values($vno,'$fn')";

 mysql_query($s1) or die("INSERT ".mysql_error());
 mysql_query("commit") or die("commit fail ".mysql_error());
 
 echo "<br>Record Successfully Added"; 

?>

<a href="paging.php">View Gallery</a>

File Name : paging.php


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paging Demo for Image Gallery</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost","root","");
mysql_select_db("dbtest");//database name
$page=0;
if(isset($_POST["page"]))
{
 $page=$_POST["page"];
 $page=($page*9)-9;//counting for 9 image is displayed in one page
}
$res = mysql_query("select *from img limit $page,9");//set limit to display 9 images
while($row=mysql_fetch_array($res))
{
 ?>
    <img src="<?php echo "./images/".$row["path"];?>" height="300" width="440px"/>
    <?php
}
$res1 = mysql_query("select *from img");
$count=mysql_num_rows($res1);//use for count how many images in database
$a=$count/9;
$a=ceil($a);//ceil function is used to round up figure
echo "<br><br>";
?>
<form method="post">
<?php
for($b=1;$b<=$a;$b++)
{
 ?>
    <input type="submit" value="<?php echo $b;?>" name="page">
    <?php
}?>

</body>

</html>

Note :-  Database Name : dbtest
            Table Name : img
            Column Name : id , path



Like us on Facebook

Site Visitor

Powered by Blogger.