쿼리에서 얻은 PHP 배열을 어떻게 가져 와서 다음과 같이 만드나요?
["14-11-2016","15-11-2016"]
나는 이것을 시도했다 :
$result=$connection->query("select day from blockades");
while($row=mysqli_fetch_assoc($result)){
echo json_encode($row['day']);
echo ",";
}
그것은 나에게 준다 :
"1-11-2016","2-11-2016","3-11-2016","4-11-2016",
하지만 자바 스크립트 배열에 넣으려고 할 때
var Array=<?php
while($row=mysqli_fetch_assoc($result)){
echo json_encode($row['day']);
}
?>
console.log(Array)
분명히 작동하지 않습니다. 콘솔은 다음을 기록합니다.
function Array() { [native code] }
jquery-ui.js:9244 Uncaught TypeError: Cannot read property 'prototype' of undefined(…)
console.log는 아무것도 제공하지 않기 때문에 js 배열에 아무것도 쓰는지 모르겠습니다. 누구나 도울 수 있습니까?
문제는 각각의 개별 항목을 인코딩하지만 전체 항목 목록을 인코딩해야한다는 것입니다.
<?php
// Create array to hold all items.
$days = array();
$result = $connection->query("select day from blockades");
// Add the days to the array.
while($row = mysqli_fetch_assoc($result)){
$days[] = ($row['day']);
}
// Output the JavaScript variable:
?>
<script type="text/javascript">
var Days=<?php echo json_encode($days) ?>;
console.log(Days);
</script>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다