I'm build an hybrid app based on JqueryMobile. And now I'm trying to get a simple array with the categorys that I select from my mysql table. I saw many questions related to this and tired a thousand solutions but nothing worked.
Here's what I have:
PHP Code:
$sql=mysql_query("SELECT Tipo FROM tfc_db.Category ");
$id=array();
while($row = mysql_fetch_assoc($sql)) {
$id[] = $row;
//$id[] = $row['Tipo']; doesn't work either
}
echo json_encode($id);
mysql_close($conn);
with this I get blank result.
The closest I got was with this:
$id=array();
$i=0;
while ($row = mysql_fetch_assoc($sql)) {
$id[] = array("data$i" => $row['Tipo']);
echo json_encode($id[$i]);
$i++;
}
with the result:
{"data0":"Restaurantes"}{"data2":"Shopping"}{"data3":"Eventos"}{"data4":"Hoteis"}{"data5":"Oficinas"}{"data6":"Combustiveis"}
but this is obviously wrong because it has multiple json_encode invocations.
Im trying to get it with Jquery's .$get
<script type="text/javascript">
var inicio=function(argument){
$("#submit").click(function(e){
e.preventDefault();
$.get('http://myurl/get_category.php',{
},function(answer){
alert(answer.length+" "+answer); //trying to know whats happening with the data.
for (var i = 0; i < answer.length; i++) { //my final objective is to fill a listview.
$('#list').append("<li> <h3>"+answer.tipo+"</h3></a></li>");
}
$('#list').listview('refresh');
},"json"
);
});
}
$(document).on('ready',inicio);
</script>
As I said I searched into many questions and solutions but always got null values. I don't have too much experience with PhP and this is me studying and making experiences with JqueryMobile so.. something's wrong here that I can't see..
Thank you.