0% found this document useful (0 votes)
7 views4 pages

3 PHP

The document outlines the process of creating a database-driven web application using PHP and MySQL, focusing on database operations such as creating tables and performing CRUD actions. It explains how to implement a live search feature using AJAX and jQuery, allowing users to see search results without refreshing the page. The document also includes code snippets for database connection, PHP interface, and backend search functionality.

Uploaded by

ridham26kamani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

3 PHP

The document outlines the process of creating a database-driven web application using PHP and MySQL, focusing on database operations such as creating tables and performing CRUD actions. It explains how to implement a live search feature using AJAX and jQuery, allowing users to see search results without refreshing the page. The document also includes code snippets for database connection, PHP interface, and backend search functionality.

Uploaded by

ridham26kamani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

504 – Web Services and Framework (TYBCA Sem-V)

Unit – 3 PHP Interaction with Database


(MySQL)
For developing database driven web applications PHP is often used in
conjunction with MySQL. You require some basic knowledge of PHP for trying out
these commands.
3.1 Create Database, Create Table, Table Handling Insert, Update,
Delete Operations

3.2 Querying database using PHP: Select, Insert, Update, Delete,


Where, order by
3.3 Processing Search query in background using AJAX
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for
creating better, faster, and more interactive web applications with the help of XML,
HTML, CSS and Java Script.
On most of the sites, we can see there is one search bar on the site where we can
type in search content and get a search result with page refreshing. A live search is a
search feature that shows the result instantly while you start typing some characters in
the search input box. You can see the search results like the Google Search
Autocomplete, Facebook, and Twitter. They have amazing live search functionality. It
makes it simpler for the clients to discover what they are looking for. It delivers the
result without page refresh. This functionality can be done using Ajax with jQuery.
With the assistance of jQuery we can utilize Ajax http dom work, with the
assistance of this capacity, it searches for information on the server side and sends back
outcome to the front end website page without a page refresh. These are the step-by-
step process to live search data using Ajax -
Step – 1 Creation of DB table

Step – 2 Script for DB connection


504 – Web Services and Framework (TYBCA Sem-V)

<?php
$con=mysqli_connect("localhost","root","XXXXX","ty2022");
if (!($con))
echo "Database Server Could not connected..".mysqli_error($con);?>

Step – 3 PHP Interface file


<?php
include("config.inc");
?>
<html>
<head>
<title>Ajax live data search using jQuery, PHP, MySQL</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
rel="stylesheet">
<script>
$(document).ready(function(){
load_data();
function load_data(query)
{
$.ajax({
url:"search.php",
method:"POST",
data:{query:query},
success:function(data)
{
$('#result').html(data);
}
});
}
$('#search').keyup(function(){
var search = $(this).val();
if(search != '')
{
load_data(search);
}
else
{
load_data();
}
});
});
</script>
</head>
<body>

SUTEX BANK COLLEGE OF COMPUTER APPLICATIONS & SCIENCE 94


504 – Web Services and Framework (TYBCA Sem-V)

<div class="container-fluid">
<div class="content-wrapper">
<div class="container">
<h1>Ajax live data search using jQuery PHP MySQL</h1>
<div class="row">
<div class="col-xs-12">
<input type="text" name="search" id="search" placeholder="Search" class="form-control" />
<!-- Following block will get filled with the data as of keyup event executes on every key stroke--
>
<div id="result">

</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

Step – 4 PHP Backend file for performing Search


<?php
require ('config.inc');
$return = '';
if(isset($_POST["query"]))
{
$search = mysqli_real_escape_string($con, $_POST["query"]);
$query = "SELECT * FROM ty2022 WHERE sid LIKE '%".$search."%' OR sname LIKE '%".$search."%';";
}
else
{
$query = "SELECT * FROM ty2022;";
}
$result = mysqli_query($con, $query);
if(mysqli_num_rows($result) > 0)
{
$return .='
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>SID</th>
<th>Roll No</th>
<th>Student Name</th>
<th>Address</th>
<th>Division</th>
<th>Birth Date</th>

SUTEX BANK COLLEGE OF COMPUTER APPLICATIONS & SCIENCE 95


504 – Web Services and Framework (TYBCA Sem-V)

</tr>';
while($ty = mysqli_fetch_row($result))
{
$return .= '
<tr>
<td>'.$ty[1].'</td>
<td>'.$ty[0].'</td>
<td>'.$ty[2].'</td>
<td>'.$ty[4].'</td>
<td>'.$ty[3].'</td>
<td>'.$ty[7].'</td>
</tr>';
}
echo $return;
}
else
{
echo 'No results found for given SID or Student Names!';
}
?>

Output

You might also like