MYSQL kullanarak DB'den bir veri almak ve javascript Array saklamak için herhangi bir yolu var mı.
Şimdiden teşekkürler
Bir associative array olarak getir, ve sonra bir dize depolanan bir JavaScript dizisini oluşturmak için json_encode kullanın.
.
// 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\">\n"
. "var users = " . json_encode($rows) . ";\n"
. "</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}
Sonra gibi bir şey yapabilirsiniz
<script type="text/javsacript">
var abc = "<? echo json_encode($arr);?>";
</script>
VEYA
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: Tabi JSON egzersiz çok ve daha yalındır olabilir olacak ...