[英]Display mysql results in javascript array
This is an javascript array where you put images and their are displayed: 这是一个放置图像的javascript数组,并显示图像:
orakuploader_attach_images: ['cat.jpg', 'dolphin.jpg', 'lion.jpg'],
Now i have a database where I want to grab the images from database and want to add them to this array somehow. 现在我有一个数据库,我想从数据库中获取图像并将其以某种方式添加到该数组中。 So how can I fetch the names from the database and put them in this array so they are displayed properly?
那么,如何从数据库中获取名称并将其放入此数组中,以便正确显示它们?
Any ideas? 有任何想法吗?
orakuploader_attach_images.push("fourth.jpg");
Or you can include a php file by: 或者,您可以通过以下方式添加php文件:
var orakupload_attach_images = <?php include(array_image.php); ?>
The file array_image.php
will have the array of images from your database: 文件
array_image.php
将包含数据库中的图像数组:
echo json_encode(array('cat.jpg', 'dolphin.jpg', 'lion.jpg'));
Or call them by Ajax: 或通过Ajax致电给他们:
$.get( "array_image.php", function( data ) {
var orakupload_attach_images = data;
/* DO THE REST OF YOUR ACTION HERE */
});
This was my solution: 这是我的解决方案:
orakuploader_attach_images: [
<?php while($e=$get_photos_query->fetch(PDO::FETCH_BOTH))
{
echo "'".$e['photo_name']."',";
}
?>],
var len = <?php echo count($phpArr); ?>
var jsArr= <?php echo json_encode($phpArr); ?>;
for(var i=0; i<len; i++){
console.log(jsArr[i]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.