Skip to main content

Mobile web apps - front-end and back-end sample

This code sample is to demonstrate how to develop a mobile web apps using HTML + jquerymobile as the front-end, and PHP+mySQL to serve as the online database.

DOWNLOAD both front-end and back-end codes here –> https://drive.google.com/file/d/0B34ZxOOoeSDdRHNvUWt6eWktbmc/view?usp=sharing

The FRONT-END

Screenshot_2015-04-22-23-53-08Screenshot_2015-04-22-23-54-27

Pls change the app’s ID in the config.xml.

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.yourhosting.yourappID"
versionCode = "2"
version = "1.0.2" >
<!-- versionCode is optional and Android only -->
<name>JPA Directory App</name>
<description>
Directory for JPA
</description>
<author href="http://kerul.net" email="khirulnizam@gmail.com">
Khirulnizam Abd Rahman
</author>
<gap:splash src="splash.png" />
<icon src="icon.png" />
</widget>


Change the link to your web server. The buttons “SEARCH AJAX”, “SEARCH STAFF” and “ADD NEW STAFF” require connection to your web server (back-end). Change the links accordingly.


*this tutorial might help you to generate Android APK file for the front-end.


 


The BACK-END


On the back-end, we are using PHP as the server-script and mySQL as the database. Inside the folder of the server-script, you will find file


SQLdump - The database sql-dump is available in jpa_dir.sql


Config file - Please change the config.php file to connect to your database.


<?php
$servername = "localhost";//change your db servername
$username = "root";//change to your db username
$password = "";//change to your password here (if any)
$dbname = "YOU_DB_NAME";//change your DB name here

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//echo "Connected successfully";
?>


Header file – the header.php contains the header for the HTML template of the page.


<!DOCTYPE html>
<html>
<head>
<title>JPA Directory</title>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/themes/test-theme2.css" />
<link rel="stylesheet" href="css/themes/jquery.mobile.icons.min.css" />
<script src="js/jquery-1.11.1.min.js"></script><script src="js/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div data-role="header" data-add-back-btn="true" data-back-btn-text="Back" data-position="fixed">
<h1>JPA Directory</h1>
</div><!-- /header -->


Footer file – the footer.php contains the header for the HTML template of the page.




<!-- footer -->
<div data-role="footer" data-position="fixed">
<h2>Copyright @2015 JPA</h2>
</div><!-- end footer -->

dy>
</html>


Search facilities


The search facilities contains two files; list-staff.php and view-staff.php .


The list-staff.php is to generate list of all record of the table sd_users and populate the data in a filterable. Selecting one of the record as in figure below will invoke another page, view-staff.php.


Screenshot_2015-04-22-23-56-44


<?php
header("Access-Control-Allow-Origin: *");//this to allow page to be accessed from the mobile app
include "config.php";
include "header.php";
//search facilities
?>

<div role="main" class="ui-content">

<?php

//sql statement
$sql = "SELECT * FROM sd_users";
//return the resultset
$result = mysqli_query($conn, $sql);

if (!$result) {//sql query error
die(mysqli_error($conn));
}
?>
<form class="ui=filterable">
</form>
<ul data-role="listview" data-inset="true" data-filter-placeholder="Find staff..."
data-filter="true">

<?php
if (mysqli_num_rows($result) > 0) {//records found
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$url="<a href='view-staff.php?id=".$row["id"]."'>";
echo "<li>".$url.$row["name"]."</a></li>";
}
} else {
echo "<li>No record found</li>";
}
?>
<ul>
</div> <!-- end main div -->
<?php
mysqli_close($conn);

include "footer.php";
?>



 


Screenshot_2015-04-22-23-57-14


The view-staff.php will display all information of the selected staff.


<?php
include "config.php";
include "header.php";
//view complete staff info
?>
<div role="main" class="ui-content">
<h2>View staff's full info</h2>
<?php
$id=$_GET["id"];
//sql statement
$sql = "SELECT * FROM sd_users WHERE id='$id'";
//return the resultset
$result = mysqli_query($conn, $sql);

if (!$result) {//sql query error
die(mysqli_error($conn));
}
//fetch the record
if (mysqli_num_rows($result) > 0) {//records found
$row = mysqli_fetch_assoc($result);
?>
<img src="images/man.png">
<form id="view-staff" name="view-staff">
<label for="txtname">Staff name</lable>
<input name="txtname" id="txtname" type="text"
value="&lt;?=$row['name'] ?>" readonly>

<label for="txtemail">Email</lable>
<a href="mailto:&lt;?=$row['email'] ?>"
class="ui-btn ui-btn-inline ui-icon-mail ui-btn-icon-right ui-btn-icon-notext ui-btn-corner-all"> </a>
<input name="txtemail" id="txtemail" type="text"
value="&lt;?=$row['email'] ?>" readonly>

<label for="txtphone">Phone</lable>
<a href="tel:&lt;?=$row['phone'] ?>"
class="ui-btn ui-btn-inline ui-icon-phone ui-btn-icon-right ui-btn-icon-notext ui-btn-corner-all"> </a>
<input name="txtphone" id="txtphone" type="text"
value="&lt;?=$row['phone'] ?>" readonly>

</form>

<?php

} //staff id exist
else {
echo "Staff not exist";
}
?>


</div> <!-- end main div -->
<?php
mysqli_close($conn);

include "footer.php";
?>


INSERTing a new record – is accomplished in the insert-new-staff.php. In this page we’re utilizing the window.location facility in JavaScript to redirect to list-staff.php after a new record is successfully saved to database.


Screenshot_2015-04-22-23-58-36Screenshot_2015-04-22-23-58-45


<?php
include "config.php";
include "header.php";
//insert facilities
?>
<div role="main" class="ui-content">
<h2>Add new staff</h2>
<form id="view-staff" name="view-staff" method="post" action="">
<label for="txtname">Staff name*</label>
<input name="txtname" id="txtname" type="text">

<label for="txtemail">Email</label>
<input name="txtemail" id="txtemail" type="text">

<label for="txtphone">Phone</label>
<input name="txtphone" id="txtphone" type="text">

<label for="dept">Department</label>
<select name="dept" id="dept">
<option value="IT">IT</option>
<option value="HR">HR</option>
<option value="Acount">Account</option>
</select>
<input type="submit" name="btnsubmit" id="btnsubmit"
value="Save record">
</form>

<?php

//checking data
if (isset($_POST["txtname"])){
$name=$_POST["txtname"];
$phone=$_POST["txtphone"];
$email=$_POST["txtemail"];
$dept=$_POST["dept"];
//sql statement
$sql = "INSERT into sd_users (name,email,phone,department) VALUES ('$name','$phone',
'$email','$dept')"
;
//check the sql command
$result = mysqli_query($conn, $sql);
if (!$result) {//sql query error
die(mysqli_error($conn));
}
//to confirm record saved
if(mysqli_affected_rows($conn)>0){
echo "The new staff has been recorded...";
echo "<a href='list-staff.php'
class='ui-btn ui-corner-all ui-icon-back
ui-btn-icon-left'> Search Staff</a>"
;
echo "<script>";
echo "window.alert('The new staff has been recorded...');";
echo "window.location='list-staff.php';";
echo "</script>";
}
}//end if data checking
include "footer.php";
?>
</div>








Again the complete codes are as below


DOWNLOAD both front-end and back-end codes here –> https://drive.google.com/file/d/0B34ZxOOoeSDdRHNvUWt6eWktbmc/view?usp=sharing

Comments

Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – https://play.google.com/store/apps/details?id=net.kerul.peribahasa English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur http://books.google.com.my/books/about/Peribahasa_dan_ungkapan_Inggeris_Melayu.html?id=bgwwQwAACAAJ CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

Contact Us at blog.kerul.net

Powered by EMF HTML Contact Form

Login JSON Android using Login Activity

I’ve been trying to release this tutorial quite a while. At last after a long hard effort. Since HttpClient is not supported any more in Android SDK 23, I have to resort to org.json.JSONObject and java.net.HttpURLConnection library to do online database with JSON. The objective of this tutorial is to log-in from a mobile client with the username and password stored in an online database facility. STEP 1: Create a new Android project, this time choose the LoginActivity .

Bootstrap Template for PHP database system - MyCompanyHR

HTML without framework is dull. Doing hard-coded CSS and JS are quite difficult with no promising result on cross platform compatibility. So I decided to explore BootStrap as they said it is the most popular web framework. What is BootStrap? - Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first web sites. (  http://www.w3schools.com/bootstrap/   ) Available here -  http://getbootstrap.com/ Why you need Flat-UI? Seems like a beautiful theme to make my site look professional. Anyway you could get variety of BootStrap theme out there, feel free to select here  http://bootstraphero.com/the-big-badass-list-of-twitter-bootstrap-resources/ Flat-UI is from DesignModo -   http://designmodo.com/flat/ Web Programming MyCompanyHR – PHP & MySQL mini project (with Boostrap HTML framework) Template 1: Template for the Lab Exercise. This is a project sample of a staff record management system. It has the PHP structured co

WebDev

http://blog.kerul.net PHP DEVELOPMENT TOOLS Download the XAMPP latest version from www.apachefriends.org . This installation file contains the Apache web server, PHP 5 and 4 interpreter, and the MySQL 5 Community edition. - download latest version MozillaFireFox (OpenSource web browser firefox) – download latest version Google Chrome – fastest web browser on earcth – fast download chrome here TEACHING PLAN Download the teaching plan here for Web/Internet Programming ( download ) NOTES HTML references HTML Editor -  http://www.sublimetext.com/ Lab 1: HTML Basics -  http://www.w3schools.com/html/ Lab 2: Responsive Design:  http://www.w3schools.com/html/html_responsive.asp Lab 3: HTML Forms  http://www.w3schools.com/html/html_forms.asp Lab 4: HTML 5  http://www.w3schools.com/html/html5_intro.asp Lab 5: Bootstrap for responsive Web -  http://www.w3schools.com/bootstra