Jquery mobile each loop over JSON not working -


i have mobile app, first page shows list of categories, when click on 1 category go second page passing category id on url , showing list of business names under category.
data on mysql i'm using json
working ok, instead of showing list of business names, shows first business repeated 14 times (each business has 14 fields), instead of looping on 5 business under 1 category, looks looping inside fields of first business of category , repeating business name.

here jquery:

$('#businesslistpage').live('pageshow', function(event) {     var id = geturlvars()["id"];     $.getjson(serviceurl + 'getbusiness.php?id='+id, displaybusiness); });  function displaybusiness(data) {     var business = data.item;     console.log(business);     $.each(business, function(index)  {         $('#actionlist').append('<li><a href="">' +              business.business + '</a></li>'); })     $('#actionlist').listview('refresh');  }  function geturlvars() {     var vars = [], hash;     var hashes = window.location.href.slice(window.location.href.indexof('?') + 1).split('&');     for(var = 0; < hashes.length; i++)     {         hash = hashes[i].split('=');         vars.push(hash[0]);         vars[hash[0]] = hash[1];     }     return vars; } 

this html

 <div id="businesslistpage" data-role="page" data-add-back-btn="true">         <div data-role="header">         <h1>business list</h1>     </div>    <div data-role="content">   <ul id="actionlist" data-role="listview" data-inset="true"></ul> 

i tried lot of stuff i'm not @ jquery, appreciate help. thanks

**add this:

this php if helps... have normalized table linke categories business, tested select part , working well.

<?php include 'config.php';  $sql = "select * " .          "from directory2 id in(select dirid cat2dir catid =:id)group business order business ";   try {     $dbh = new pdo("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);       $dbh->setattribute(pdo::attr_errmode, pdo::errmode_exception);     $stmt = $dbh->prepare($sql);       $stmt->bindparam("id", $_get[id]);     $stmt->execute();     $businesses = $stmt->fetchobject();       $dbh = null;     echo '{"item":'. json_encode($businesses) .'}';          } catch(pdoexception $e) {     echo '{"error":{"text":'. $e->getmessage() .'}}';  } 

?>

as far can infer code json has key name want loop.

change each to

$.each(business, function(index)  {         $('#actionlist').append('<li><a href="">' +              index.business + '</a></li>'); }); 

you have used business.business . may causing problems.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

java - More than one row with the given identifier was found: 1, for class: com.model.Diagnosis -