Saturday, 19 March 2016
Jquery Validation using validate.js for beginners
Create index.html file and put this code bellow. :)
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css">
<style type="text/css">
.label {width:100px;text-align:right;float:left;padding-right:10px;font-weight:bold;}
#RegisterFrom label.error, .output {color:#FB3A3A;}
</style>
</head>
<body>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form action="" method="post" id="RegisterFrom" novalidate="novalidate" role="form" >
<div class="col-md-12">
<h2 class='text-primary text-center'>Register From</h2>
</div>
<div class='col-md-12'>
<input type="text" id="name" name="name" placeholder="Full Name" class='form-control'/><br>
</div>
<div class='col-md-12'>
<select id="gender" name="gender" class='form-control'>
<option value="">Select Gender</option>
<option value="Female">Female</option>
<option value="Male">Male</option>
<option value="Other">Other</option>
</select><br>
</div>
<div class='col-md-12'>
<input type="text" id="address" name="address" placeholder="Address" class='form-control'/><br>
</div>
<div class='col-md-12'>
<input type="text" id="email" name="email" placeholder="Email address" class='form-control'/><br>
</div>
<div class='col-md-12'>
<input type="text" id="username" name="username" placeholder="Username" class='form-control'/><br>
</div>
<div class='col-md-12'>
<input type="password" id="password" name="password" placeholder="Password" class='form-control'/><br>
</div>
<div class='col-md-12'>
<input type="submit" name="submit" value="Submit" class='btn btn-success' />
</div>
</form>
</div>
</div>
<script src="//code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript"></script>
<script>
// When the browser is ready...
$(function () {
// Setup form validation on the #register-form element
$("#RegisterFrom").validate({
// Specify the validation rules
rules: {
name: "required",
gender: "required",
address: "required",
email: {
required: true,
email: true
},
username: "required",
password: {
required: true,
minlength: 5
}
},
// Specify the validation error messages
messages: {
name: "Please enter your name",
gender: "Please specify your gender",
address: "Please enter your address",
email: "Please enter a valid email address",
username: "Please enter a valid username",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
}
},
submitHandler: function (form) {
form.submit();
}
});
});
</script>
</body>
</html>
Thursday, 17 March 2016
Jquery Data table and paging
Set perfect view of table with use of jquery data table
Step 1 : create php file name 'index.php' and insert a code bellow .
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$dbname = "Jquerydb";
$con = mysqli_connect($hostname, $username, $password, $dbname);
$query = "SELECT * FROM trn_movies";
$result = mysqli_query($con, $query);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Jquery datatable demo</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css">
</head>
<body>
<div style="margin:0 auto; text-align:center; width:80%">
<h3>Jquery DataTable demo(PHP, MYSQL)</h3>
<table id="stdcode" class="table table-striped table-bordered dataTable" cellspacing="0" width="100%" role="grid" aria-describedby="example_info" style="width: 100%;">
<thead>
<tr >
<th>Film Name</th>
<th>Director</th>
<th>Release Year</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<?php $sn = 1;
foreach ($result as $resultSet) { ?>
<tr>
<th><?= $resultSet['film_name'] ?></th>
<th><?= $resultSet['director'] ?></th>
<th><?= $resultSet['release_year'] ?></th>
<th><?= $resultSet['movie_id'] ?></th>
</tr>
<?php $sn++;
} ?>
</tbody>
</table>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="//cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.10/js/dataTables.bootstrap.min.js"></script>
<script>
$(function () {
$('#stdcode').DataTable();
});
</script>
</body>
</html>
Step 2 : Create db ('Jquerydb') and add table ('trn_movies') and fire this two queries .
CREATE TABLE `trn_movies` (
`movie_id` int(10) UNSIGNED NOT NULL,
`film_name` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`director` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
`release_year` int(10) UNSIGNED NOT NULL
);
--
-- Dumping data for table `trn_movies`
--
INSERT INTO `trn_movies` (`movie_id`, `film_name`, `director`, `release_year`) VALUES
(1, 'Happy New Year', 'Farah Khan', 2014),
(2, 'Kill Dil', 'Shaad Ali', 2014),
(3, 'The Shaukeens', 'Abhishek Sharma', 2014),
(4, 'Kick', 'Sajid Nadiadwala', 2014),
(5, 'Bang Bang', 'Siddharth Anand', 2014),
(6, 'Ungli', 'Rensil DSilva', 2014),
(7, 'Happy Ending', ' Krishna D.K', 2014),
(8, 'Jai Ho', 'Sohail Khan', 2014),
(9, 'Lingaa', 'K. S. Ravikumar', 2015),
(10, 'Daawat-e-Ishq', 'Habib Faisal', 2014),
(11, 'Singham Returns', 'Rohit Shetty', 2014);
(12, 'Kill Dil', 'Shaad Ali', 2014),
(13, 'The Shaukeens', 'Abhishek Sharma', 2014),
(14, 'Kick', 'Sajid Nadiadwala', 2014),
(15, 'Bang Bang', 'Siddharth Anand', 2014),
(16, 'Ungli', 'Rensil DSilva', 2014),
(17, 'Happy Ending', ' Krishna D.K', 2014),
(18, 'Jai Ho', 'Sohail Khan', 2014),
(19, 'Lingaa', 'K. S. Ravikumar', 2015),
(20, 'Daawat-e-Ishq', 'Habib Faisal', 2014),
(21, 'Singham Returns', 'Rohit Shetty', 2014);
(22, 'Kill Dil', 'Shaad Ali', 2014),
(23, 'The Shaukeens', 'Abhishek Sharma', 2014),
(24, 'Kick', 'Sajid Nadiadwala', 2014),
(25, 'Bang Bang', 'Siddharth Anand', 2014),
(26, 'Ungli', 'Rensil DSilva', 2014),
(27, 'Happy Ending', ' Krishna D.K', 2014),
(28, 'Jai Ho', 'Sohail Khan', 2014),
(29, 'Lingaa', 'K. S. Ravikumar', 2015),
(30, 'Daawat-e-Ishq', 'Habib Faisal', 2014),
(31, 'Singham Returns', 'Rohit Shetty', 2014);
Wednesday, 16 March 2016
Display pointer in Google Map for beginners
Just 3 step to display pointer address from your database to google map
Step 1 : Create table 'marker' in database name 'excel'
CREATE TABLE IF NOT EXISTS `markers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(60) NOT NULL,
`address` varchar(80) NOT NULL,
`lat` float(10,6) NOT NULL,
`lng` float(10,6) NOT NULL,
`type` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=19 ;
INSERT INTO `markers` (`id`, `name`, `address`, `lat`, `lng`, `type`) VALUES
(1, 'PromtWebSolution', 'Ahmedabad,SG Highway', 23.030510, 72.505730, '')
Step 2 : create a php file name 'phpsqlxml_genxml.php' for db connection and get data from table.
<?php
function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}
// Opens a connection to a MySQL server
$connection=@mysql_connect ("localhost", "root","");
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = @mysql_select_db("excel", $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Select all the rows in the markers table
$query = "SELECT * FROM markers WHERE 1";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Start XML file, echo parent node
echo '<markers>';
// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
echo '<marker ';
echo 'name="' . parseToXML($row['name']) . '" ';
echo 'address="' . parseToXML($row['address']) . '" ';
echo 'lat="' . $row['lat'] . '" ';
echo 'lng="' . $row['lng'] . '" ';
echo 'type="' . $row['type'] . '" ';
echo '/>';
}
// End XML file
echo '</markers>';
?>
Step 3 : create 'index.html' file for view address pointer on google map.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps AJAX + mySQL/PHP Example</title>
<script src="http://maps.google.com/maps/api/js?sensor=false"type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var customIcons = {
restaurant: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
},
bar: {
icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
}
};
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(47.6145, -122.3418),
zoom: 13,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var point = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,position: point,icon: icon.icon,shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?new ActiveXObject('Microsoft.XMLHTTP') :new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
</head>
<body onload="load()">
<div id="map" style="width: 500px; height: 500px"></div>
</body>
</html>
Friday, 11 March 2016
Wednesday, 9 March 2016
Facebook Likes Count with PHP
Get Facebook Likes Count with PHP
STEP 1 :First we make a function that will pass one parameter and that parameter is our link.
function fb_count($url)
{
}
STEP 2 : Then under this function first we make a query and ask it to SELECT share_count, like_count and comment_count from a table named link_stat. Obviously we need a KEY for for it so our Link or URL will be the KEY for this query.
$fql = "SELECT share_count, like_count, comment_count ";
$fql .= " FROM link_stat WHERE url = '$url'";
STEP 3 : Then we use Facebook API to pass above Query. After passing this query we will get our response in JSON.
$fqlURL = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);
STEP 4 : When facebook response us in JSON we need to decode that JSON it can be through Buil-in function json_decode().
$response = file_get_contents($fqlURL);
return json_decode($response);
STEP 5 : Now it’s time to pass our Link or URL to get likes, shares and comments. Simply I use finction fb_count() and provide it a parameter as a Link or URL
$fb = fb_count('our link set here');
Now we have to echo that response.
1 - For facebook Shares Count
echo $fb[0]->share_count;
2 - For facebook Like Count
echo $fb[0]->like_count;
3 - For facebook Like Count
echo $fb[0]->comment_count;
Enjoy.......... :)
Enjoy.......... :)
Tuesday, 8 March 2016
Load CSS in CodeIgniter
Perfect way to load css, js, images and other assets in codeigniter
Step 1 : To attach a CSS, JS, Images .etc you just have to do is go to your config folder and write at the end of the constant.php file.
constant.php
define('CSS',URL.'public/css/');
define('IMAGES',URL.'public/images/');
define('JS',URL.'public/images/');
Step 2 : After that goto your view and in the link just add
<link rel="stylesheet" type="text/css" href="<?php echo CSS; ?>mystyle.css">
<link rel="stylesheet" type="text/css" href="<?php echo CSS; ?>mystyle.css">
Friday, 4 March 2016
Display data with AngularJS
STEP 1 : CREATE 'index.php' AND WRITE THIS CODE IN IT
<html ng-app="fetch">
<head>
<title>AngularJS GET request with PHP</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
<br>
<div class="row">
<div class="container">
<h1>Angular $http GET Ajax Call In Database</h1>
<div ng-controller="dbCtrl">
<input type="text" ng-model="searchFilter" class="form-control" placeholder="Search Contry">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Nicename</th>
<th>ISO</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="country in data| filter:searchFilter">
<td>{{country.name}}</td>
<td>{{country.nicename}}</td>
<td>{{country.iso}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src="jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.min.js"></script>
<script>
var fetch = angular.module('fetch', []);
fetch.controller('dbCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get("GetData.php")
.success(function (data) {
debugger;
$scope.data = data;
console.log(data);
})
.error(function () {
$scope.data = "error in fetching data";
});
}]);
</script>
</body>
</html>
STEP 2 : IN 'GetData.php' , WRITE THIS CODE FOR GET DATA FROM country TABLE
<?php
//database settings
$connect = mysqli_connect("localhost", "root", "", "fruxinfo_o_cart");
$result = mysqli_query($connect, "select * from country");
$data = array();
while ($row = mysqli_fetch_array($result)) {
$data[] = $row;
}
print json_encode($data);
?>
STEP 3 :CREATE DATABASE 'countrydb' AND IMPORT THIS TABLE QUERY
-- phpMyAdmin SQL Dump-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Mar 05, 2016 at 07:45 PM
-- Server version: 10.1.9-MariaDB
-- PHP Version: 5.6.15
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `countrydb`
--
-- --------------------------------------------------------
--
-- Table structure for table `country`
--
CREATE TABLE `country` (
`id` int(11) NOT NULL,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `country`
--
INSERT INTO `country` (`id`, `iso`, `name`, `nicename`, `iso3`, `numcode`, `phonecode`) VALUES
(1, 'AF', 'AFGHANISTAN', 'Afghanistan', 'AFG', 4, 93),
(2, 'AL', 'ALBANIA', 'Albania', 'ALB', 8, 355),
(3, 'DZ', 'ALGERIA', 'Algeria', 'DZA', 12, 213),
(4, 'AS', 'AMERICAN SAMOA', 'American Samoa', 'ASM', 16, 1684),
(5, 'AD', 'ANDORRA', 'Andorra', 'AND', 20, 376),
(6, 'AO', 'ANGOLA', 'Angola', 'AGO', 24, 244),
(7, 'AI', 'ANGUILLA', 'Anguilla', 'AIA', 660, 1264),
(8, 'AQ', 'ANTARCTICA', 'Antarctica', NULL, NULL, 0),
--
-- Indexes for dumped tables
--
--
-- Indexes for table `country`
--
ALTER TABLE `country`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `country`
--
ALTER TABLE `country`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=240;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Prompt Web Solution. Powered by Blogger.








