Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: application/json');
- //--------------------------------------------------------------------------
- // Example php script for fetching data from mysql database
- //--------------------------------------------------------------------------
- $host = "localhost";
- $user = "";
- $pass = "";
- $databaseName = "";
- $tableName = "suggestions";
- //--------------------------------------------------------------------------
- // 1) Connect to mysql database
- //--------------------------------------------------------------------------
- $con = mysql_connect($host,$user,$pass);
- $dbs = mysql_select_db($databaseName, $con);
- $name=$_REQUEST['name'];
- //--------------------------------------------------------------------------
- // 2) Query database for data
- //--------------------------------------------------------------------------
- $result = mysql_query("SELECT * FROM $tableName where name like '$name%%'"); //query
- //$array = mysql_fetch_row($result); //fetch result
- $rows = array();
- while($r = mysql_fetch_assoc($result)) {
- $rows['results'][] = $r;
- }
- //--------------------------------------------------------------------------
- // 3) echo result as json
- //--------------------------------------------------------------------------
- echo json_encode($rows);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement