Skip to content

Instantly share code, notes, and snippets.

@simonwh
Created April 27, 2010 09:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simonwh/380536 to your computer and use it in GitHub Desktop.
Save simonwh/380536 to your computer and use it in GitHub Desktop.
var search = Titanium.UI.createSearchBar({
barColor:'#000',
showCancel:true,
height:43,
top:0
});
var tableView = Titanium.UI.createTableView({
top:40,
data:{title:'Please perform a search'}
});
Titanium.UI.currentWindow.add(search);
Titanium.UI.currentWindow.add(tableView);
search.addEventListener('change', function(e)
{
Titanium.API.info('search bar: you type ' + e.value + ' act val ' + search.value);
if(e.value.length > 3) {
var xhrMovieSearch = Titanium.Network.createHTTPClient();
xhrMovieSearch.onload = function() {
var matches = JSON.parse(this.responseText);
var fetchedData = [];
for(var x in matches) {
fetchedData.push({title:matches[x].title});
}
tableView.setData(fetchedData);
};
xhrMovieSearch.open('GET','myserver/do_find_movies_by_title.php?title=' + e.value);
xhrMovieSearch.send();
}
});
<?php
require_once('dbconnect.php');
function find_movies_by_title($title) {
$q = mysql_query("SELECT * FROM `movies` WHERE `title` LIKE '%$title%'");
$matches = array();
$i = 1;
while($row = mysql_fetch_assoc($q)) {
$matches[$i]['title'] = $row['title'];
$matches[$i]['year'] = $row['year'];
$i++;
}
return $matches;
}
echo json_encode($matches);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment