Created
April 27, 2010 09:22
-
-
Save simonwh/380536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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