是否有任何可能的方法从使用MYSQL并储存在javascript Array的亚洲开发银行获得数据?
• 如何从亚洲开发银行获得使用MYSQL并储存在javascript Array的数据
原标题:how to get a data from a DB using MYSQL and store it in javascript Array
问题回答
Fetch it as an associative protocol,然后使用json_encode ,创建 Java式阵列,储存在地体内。
。
// first, build your query:
$sql = "SELECT name, email FROM users";
$result = mysql_query($sql);
// then build up your data
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
//then write it in a way Javascript can understand:
echo "<script type="text/javascript">
"
。 "var users = " 。 json_encode($rows) 。 ";
"
。 "</script>";
<?php
$arr = array ( a =>1, b =>2, c =>3, d =>4, e =>5);
// of course this array can be created by looping through your mysql result set
// and doing a mysql_fetch_assoc
// for example, $sql = your query here
// mysql_fetch_assoc($result); etc
echo json_encode($arr);
?>
{"a":1,"b":2,"c":3,"d":4,"e":5}
然后,你可以做这样的事情。
<script type="text/javsacript">
var abc = "<? echo json_encode($arr);?>";
</script>
页: 1
echo <script type="text/javsacript">
var abc =" .json_encode($arr). ";
</script> ;
Actually this is a pretty vague question, but I think AJAX is what you re looking for.
EDIT:当然,JSON也将工作,甚至可能更直截了当。
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding