Title: datalist data from mysql
Post by: Szoron on March 13, 2015, 07:48:32 AM
Hello! I was preparing to give a mobile database interface. How can I spit out a list-data in the returned data from mysql? Thank you in advance for your help! Most ez a forráskód: <!DOCTYPE html> <html>
<body> <div class="easyui-navpanel" style="position:relative;padding:20px"> <header> <div class="m-toolbar"> <div> <input class="easyui-datebox" name='d' id='d' prompt="Dátum" data-options="editable:false,panelWidth:220,panelHeight:240,iconWidth:30" style="width:100%"> </div> </div> </header>
<ul class="easyui-datalist" data-options=" fit: true, lines: true, url: 'sql_address.php', method: 'get', border: false, textFormatter: function(value){ return '<a href\'javascript:void(0)\' class=\'datalist-link\'>' + value + '</a>'; }, onClickRow: function(index,row){ $('#p2-title').html(row.addr); $.mobile.go('#p2'); } ">
</ul>
</div> <style scoped> form label{ display: block; margin: 10px 0 5px 0; } </style> </body> </html> <?php include 'conn.php'; mysql_query("SET NAMES 'utf8'"); mysql_query("SET CHARACTER SET utf8 "); //$act_date = mysql_real_escape_string($_REQUEST['d']); $act_date = $_POST['d']; $query = "SELECT address.efi_address AS name, work_types.name AS n, address.ml_num AS ml FROM walker4.address"; $query .= "LEFT JOIN tchs ON tchs.id = address.tch"; $query .= "LEFT JOIN work_types ON work_types.id = address.work_type"; //$query .= "WHERE address.works_date ="; //$query .= $act_date; $rs = mysql_query($query); $items = array(); while($row = mysql_fetch_object($rs)){ array_push($items, $row); } $result["rows"] = $items; echo json_encode($result);
?>
Title: Re: datalist data from mysql
Post by: Szoron on March 13, 2015, 12:38:12 PM
Upgraded code:! but no result It does not return any results <!DOCTYPE html> <html>
<body> <div class="easyui-navpanel" style="position:relative;padding:20px"> <header> <div class="m-toolbar"> <div> <input class="easyui-datebox" name='d' id='d' prompt="Dátum" data-options="editable:false,panelWidth:220,panelHeight:240,iconWidth:30" style="width:100%"> </div> </div> </header>
<ul class="easyui-datalist" data-options=" fit: true, lines: true, url: 'sql_address.php', method: 'get', valueField: 'id', textField: 'name' "> </ul> </div> <style scoped> form label{ display: block; margin: 10px 0 5px 0; } </style> </body> </html> <?php include 'conn.php'; //$rs = mysql_query("SELECT address.efi_address AS name, work_types.name AS n, address.ml_num AS ml FROM walker4.address LEFT JOIN tchs ON tchs.id = address.tch LEFT JOIN work_types ON work_types.id = address.work_type"); $rs = mysql_query("SELECT id, name, status FROM close_codes"); $result = array(); $items = array(); while($row = mysql_fetch_object($rs)){ array_push($items, $row); } $result["total"] = 5; $result["rows"] = $items; echo json_encode($result); ?>
Title: Re: datalist data from mysql
Post by: stworthy on March 13, 2015, 07:00:07 PM
Please check your 'sql_address.php' carefully on the browser to determine if there are some errors occur.
Title: Re: datalist data from mysql
Post by: thecyberzone on March 14, 2015, 09:34:09 AM
Just use echo json_encode($items); instead of writing following three lines.
$result["total"] = 5; $result["rows"] = $items; echo json_encode ($result);
Title: Re: datalist data from mysql
Post by: Szoron on March 15, 2015, 11:14:30 PM
Thanks for help Success
|