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...

Submit your blog address here

Create your own blog and send the address by submitting the comment of this article. Make sure to provide your full name, matrix and URL address of your blog. Refer to the picture below. Manual on developing a blog using blogger.com and AdSense, download here … Download Windows Live Writer (a superb offline blog post editor)

Installing Google AdMob into Android Apps

Previously I wrote on why ads are needed to help maintaining an app. Read the article here http://blog.kerul.net/2011/05/generating-revenue-from-free-mobile.html . ---This is quite an old article. You may find the latest supporting AdMob 6.x in here http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html --- This is quite a long tutorial, there are 3 major steps involved. The experiment is done using Windows 7, Eclipse Helios and AdMob SDK 4.1.0 (which currently is the latest-during time of writing). STEP 1: Get the ads from AdMob.com To display the AdMob ads in your Android mobile apps, you need to register first at the admob.com . After completing the registration, login and Add Site/App. Refer to Figure 1. Figure 1 Choose the desired platform and fill in the details (as in Figure 2). Just put http:// in the Android Package URL if your app is not published in the market yet. And click Continue. Figure 2 Download the AdMob Android SDK, and save the zip fil...

Pemasangan Joomla! 1.7 pada pelayan web komputer anda

Latihan ini akan memasang sistem pengurusan kandungan laman web ke dalam pelayan web yang anda telah pasang sebelum ini . LANGKAH 1: Aktifkan Pelayan Web dan Pangkalan Data Aktifkan XAMPP Control Panel, melalui “ Start->All Programs->ApacheFriends->XAMPP Control Panel ”. Rajah 2.1 Pastikan pelayan web Apache dan pelayan pangkalan data MySQL diaktifkan dengan klik butang START. -> Rajah 2.2

Applications of Web 2.0

Web 2.0 describes the changing trends in the use of World Wide Web technology and web design that aim to enhance creativity , secure information sharing, collaboration and functionality of the web. Web 2.0 concepts have led to the development and evolution of web-based communities and hosted services , such as social-networking sites , video sharing sites , wikis , blogs . Find a website or web application that conform to the criteria of Web 2.0. Put the name of the application and the URL in the comment below. Please provide your full name and matrix number. Make sure the application you choose is not already chosen by your friend in the previous comment.