Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

INDIEN: STD-Code-Finder-Skript in PHP, MySQL und jQuery

Hier teile ich eine nützliche Datenbank mit euch: die Liste der STD-Codes (Ortsvorwahlen) von Indien in MySQL und Excel, samt einem STD-Code-Finder-Skript in PHP, MySQL und jQuery.

Wenn du eine telekommunikationsbasierte Website planst, könnte dir das helfen. Ich stelle die komplette Datenbank samt Skript bereit. Im STD-Code-Finder habe ich die jQuery-Autocomplete-Funktion verwendet.

INDIEN: STD-Code-Finder-Skript in PHP, MySQL und jQuery

Die HTML-Datei

Erstelle deine HTML-Datei mit etwas CSS und dem benötigten JavaScript. Vergiss nicht, die jQuery-Bibliothek einzubinden.

index.html

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>INDIA, STD Code Finder Script in PHP, MYSQL, JQUERY</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> <style> .ui-autocomplete-loading { background: white url("img/ui-anim_basic_16x16.gif") right center no-repeat; } .ui-autocomplete { max-height: 300px; overflow-y: auto; overflow-x: hidden; } * html .ui-autocomplete { height: 100px; } </style> </head> <body>   <h3>INDIA, STD Code Finder Script in PHP, MYSQL, JQUERY</h3> <div class="ui-widget"> <input type="text" id="std" name="std" placeholder="Type city name or std code" style="width:550px;"><br/> <span style="color:red">* Enter atleast 3 character..!! </span> </div>   <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <script> $(function() { $( "#std" ).autocomplete({ source: function( request, response ) { $.ajax({ url: "request.php", dataType: "json", data: { q: request.term }, success: function( data ) { response( data ); } }); }, minLength: 3, select: function( event, ui ) { console.log(ui.item); }, open: function() { }, close: function() { } }); }); </script> </body> </html>

Die Serverdatei request.php

Erstelle die Serverdatei, die die Daten aus der Datenbank abruft und im JSON-Format zurückgibt.

<?php $hostname = "localhost"; $username = "username"; $password = "db-password"; $dbname = "database-name"; $q = $_GET['q']; if(isset($q) || !empty($q)) { $con = mysqli_connect($hostname, $username, $password, $dbname); $query = "SELECT * FROM stdcodes WHERE CONCAT(city, ' ', stdcode) LIKE '%$q%'"; $result = mysqli_query($con, $query); $res = array(); while($resultSet = mysqli_fetch_assoc($result)) { $res[$resultSet['id']] = $resultSet['city'].", STD-CODE: ".$resultSet['stdcode']; } if(!$res) { $res[0] = 'Not found!'; } echo json_encode($res); }   ?>

Über die Schaltfläche unten gelangst du zur Live-Demo und kannst den Quellcode samt Datenbank herunterladen.