Artificial Intelligence Programs For Programming in Python

Traveling Salesman Problem ( TSP )] Artificial Intelligence Programs For Master Leval Programming in Python from iter tools import permutations def distance(point1, point2): >>> distance([3,4],[0,0]) 5.0 >>> distance([3,6],[10,6]) 7.0 return ((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2) ** 0.5 def total_distance(points): all the points are in the given order. >>> total_distance([[1,2],[4,6]]) 5.0 >>> total_distance([[3,6],[7,6],[12,6]]) 9.0 return sum([distance(point, points[index + 1]) for index, point in enumerate(points[:-1])]) def travelling_salesman(points, start=None): Time complexity is O(N!), so never use on long lists. >>> travelling_salesman([[0,0],[10,0],[6,0]]) ([0, 0], [6, 0], [10, 0]) >>> travelling_salesman([[0,0],[6,0],[2,3],[3,7],[0.5,9],[3,5],[9,1]]) ([0, 0], [6, 0], [9, 1], [2, 3], [3, 5], [3, 7], [0.5, 9]) """ if the start is None: start = points[0] return min([perm for perm ...

How To Create Autocomplete on an Input Field PHP - C4U

AutoComplete search in PHP
AutoComplete search in PHP

How To Create Autocomplete on an Input Field PHP?

>> create one index.php file look like below
>> Add Script Below in head tag

<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(function(){
$(".search").keyup(function() 
var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
$.ajax({
type: "POST",
url: "search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}return false;    
});

});
</script>

>> Add CSS Below in head tag

<style type="text/css">
body{ 
font-family:Tahoma, Geneva, sans-serif;
font-size:18px;
display: table;
margin: 0 auto;
}
.content{
width:900px;
margin:0 auto;
}
#searchid
{
width:500px;
border:solid 1px #000;
padding:10px;
font-size:14px;
}
#result
{
position:absolute;
width:500px;
padding:10px;
display:none;
margin-top:-1px;
border-top:0px;
overflow:hidden;
border:1px #CCC solid;
background-color: white;
}





.show
{
padding:10px; 
border-bottom:1px #999 dashed;
font-size:15px; 
height:50px;
}
.show:hover
{
background:#4c66a4;
color:#FFF;
cursor:pointer;
}
</style>

>> Add Code Below in Body tag

<div class="form-group">
<input type="text" class="search" class="form-control" id="searchid" placeholder="Search for people" />&nbsp; &nbsp; Ex:Naresh Kakkad, Dhaval, Saurabh<br />
</div>
<div id="result"></div>

>> Create connection.php

$connection = mysqli_connect('localhost','root','','databasename') or die(mysql_error());

>> Create search.php

<?php

include('connection.php');
if($_POST)
{
$q=$_POST['search'];
$sql_res=mysql_query("select id,name,email from autocomplete where name like '%$q%' or email like '%$q%' order by id LIMIT 5");
while($row=mysql_fetch_array($sql_res))
{
$username=$row['name'];
$email=$row['email'];
$b_username='<strong>'.$q.'</strong>';
$b_email='<strong>'.$q.'</strong>';
$final_username = str_ireplace($q, $b_username, $username);
$final_email = str_ireplace($q, $b_email, $email);
?>
<div class="show" align="left">
<span class="name"><?php echo $final_username; ?></span>&nbsp;<br/><?php echo $final_email; ?><br/>
</div>
<?php
}
}
?>

Autocomplete input field
Download Source code to click button

Comments

Post a Comment

Popular posts from this blog

MongoDB Exercises Practice Solution Exercise First

How to Generate QR Code in PHP with jquery Learn Now

How to create Pagination with PHP and MySql - Codingpoint