I’m trying to make a mobile application using jQuery Mobile and Phonegap. But first of all I’d like to say that I’m not a professional programmer; I’m only a student trying to understand de basics of a mobile application. I do have some experience in HTML and PHP.
So I’m trying to learn myself some of the basics of a mobile application; I tried it before but due to a lack off time I did not have the time to investigate the problem I was experiencing back then.
The thing I’m trying to realize is quite simple:
I have a SQL database with: names (1), where they work(2) and a description(3). All of them have an unique ID – So 4 tables.
First thing I’d like to pull from the database is their names according from where they work.
I tried to follow several tutorials, guides and read trough some other stuff. This is what I came up with. This is a PHP-file placed on the server.
<?
include 'includes/db.php';
$sql = mysql_query("SELECT name FROM work");
$array = Array();
if(mysql_num_rows($sql) > 0)
{
for($i=0; $i < count($sql); $i++){
$rec = mysql_fetch_assoc($sql);
$array[name] = $rec['name'];
}
echo json_encode($array);
}
?>
When I open this PHP-file I do get a result back from the database, formatted in JSON. But I’m only getting one name in return while there are more names in that database.
Next I’d go and place the jQuery code in the jQuery-Mobile app like this:
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('names.php', function(data){
$("#namesDiv").html(data);
});
});
</script>
Ofcourse this is not returning anything; this I’m still trying to figure out how to display all the names as a list in the HTML file.
But after this I want to be able to tap on a name from that list and get the description from that person on a next page. I know in PHP you can get the ID from the URL (page.php?id=1) and then pass it on in your query to get the correct data; but how can this be done when JSON is handeling everything?
I hope someone can help me out; I know I’m asking a lot and that my knowledge is maybe insufficient but I would really appreciate any help I can get.
you can send
idlikeand in your names.php do
query part