I want to add an edit button on my page after searching for a particular name.
After the search, it should be displayed in a table where there would be an edit button beside each column.
How to add an edit button in search results?
Share
I want to add an edit button on my page after searching for a particular name.
After the search, it should be displayed in a table where there would be an edit button beside each column.
The first thing you can learn HTML, whether you want to become a professional web developer or just want to learn more about how websites work. The basic language for developing web pages and web applications is HTML. A server ...
Asynchronous Javascript One of AJAX’s benefits is it provides instantaneous feedback to the user because it requests information asynchronously from the backend web server. However, using AJAX does not guarantee the user will not wait for the asynchronous JavaScript and ...
How To Make Cookie Free Domain An HTTP cookie (also known as a web cookie, Internet cookie, browser cookie, or simply cookie) is a small piece of data sent from a website and stored on the user’s computer by the ...
PHP MySQL & Ajax Live Data Table Tutorial
PHP MySQL & Ajax Live Data Table Tutorial
Type a name to begin searching
Name
Company
Zip
City
Top Searches
These results are ranked by popularity in the query_data table. Each time the complete name is entered in the search, a +1 is registered and incremented.
Name
Company
Zip
City
Check out the full tutorial at LekkerLogic.com – PHP MySQL Ajax Live Data Table Tutorial
search.php
<?php
require_once 'db.php';
// Output HTML formats
$html = '’;
$html .= ’nameString’;
$html .= ’compString’;
$html .= ’zipString’;
$html .= ’cityString’;
$html .= ’’;
// Get the Search
$search_string = preg_replace(”/[^A-Za-z0-9]/”, ” ”, $_POST[’query’]);
$search_string = $test_db->real_escape_string($search_string);
// Check if length is more than 1 character
if (strlen($search_string) >= 1 && $search_string !== ’ ’) {
//Insert Time Stamp
$time = ”UPDATE query_data SET timestamp=now() WHERE name=’” .$search_string. ”’”;
//Count how many times a query occurs
$query_count = ”UPDATE query_data SET querycount = querycount +1 WHERE name=’” .$search_string. ”’”;
// Query
$query = ’SELECT * FROM live_table WHERE name LIKE ”%’.$search_string.’%”’;
//Timestamp entry of search for later display
$time_entry = $test_db->query($time);
//Count how many times a query occurs
$query_count = $test_db->query($query_count);
// Do the search
$result = $test_db->query($query);
while($results = $result->fetch_array()) {
$result_array[] = $results;
}
// Check for results
if (isset($result_array)) {
foreach ($result_array as $result) {
// Output strings and highlight the matches
$d_name = preg_replace(”/”.$search_string.”/i”, ””.$search_string.””, $result[’name’]);
$d_comp = $result[’company’];
$d_zip = $result[’zip’];
$d_city = $result[’city’];
// Replace the items into above HTML
$o = str_replace(’nameString’, $d_name, $html);
$o = str_replace(’compString’, $d_comp, $o);
$o = str_replace(’zipString’, $d_zip, $o);
$o = str_replace(’cityString’, $d_city, $o);
// Output it
echo($o);
}
}else{
// Replace for no results
$o = str_replace(’nameString’, ’No Names Found’, $html);
$o = str_replace(’compString’, ’’, $o);
$o = str_replace(’zipString’, ’’, $o);
$o = str_replace(’cityString’, ’’, $o);
// Output
echo($o);
}
}
?>
topsearch.php
query($query);
while($results = $result->fetch_array()) {
$result_array[] = $results;
}
foreach ($result_array as $result) {
// The output
echo ’’;
echo ’’.$result[’name’].’’;
echo ’’.$result[’company’].’’;
echo ’’.$result[’zip’].’’;
echo ’’.$result[’city’].’’;
echo ’’;
}
?>
I have checked your code. You have to follow the below steps to add the edit button into you ajax search.
Go to index.php and add:
Action on line number 77
Then open your search.php file and add: $html .= ’edit’; on line number 9
On the same file you have to add:
$getId = $result[’id’];
$getlink = ” Edit ”; on line 44
And after adding the above code.. Please add: $o = str_replace(’edit’, $getlink, $o);
below of: $o = str_replace(’cityString’, $d_city, $o);
Now you will get the edit button in your search results.
After that you have to create a new file with the edit.php name and add the edit code on that and that’s all your.
Thanx