Arrays 如何将数据库放入数组中

Arrays 如何将数据库放入数组中,arrays,database,Arrays,Database,我最终成功地使用php制作了一个图像旋转木马。 下面的代码起作用,但其中没有图像。 现在,我正在尝试使用此数组从Mysql数据库获取数据。 你能给我举个我该怎么做的例子吗 <?php //MySQL database connection $mysqli = new mysqli('localhost', 'root', '', 'webshop'); $SQL = "SELECT image FROM productlist LIMIT 5"; $

我最终成功地使用php制作了一个图像旋转木马。
下面的代码起作用,但其中没有图像。
现在,我正在尝试使用此数组从Mysql数据库获取数据。
你能给我举个我该怎么做的例子吗

   <?php

    //MySQL database connection
    $mysqli = new mysqli('localhost', 'root', '', 'webshop');
    $SQL = "SELECT image FROM productlist LIMIT 5";
    $result = $mysqli->query($SQL);


    $array = array(
        0 => "picture1.jpg",
        1 => "picture2.jpg",
        2 => "picture3.jpg",
        3 => "picture4.jpg",
        4 => "picture5.jpg",
        5 => "kalle6.jpg",
    );

    //Goes to previous page when clicking on prev
    $index = $_GET['start'];

    if ($index > 0) {
        echo '<a href="index.php?start=' . ($index - 1) . '"> prev </a> ';
    } else {
        echo '<a href="index.php?start=' . (count($array) - 1) . '"> prev </a> ';
    }

    //Display 3 images
    $show_img = 3;
    $num_img = 0;
    for($i = $_GET['start']; $i<count($array) && $num_img < $show_img; $i++) {
        $num_img++;
        echo "<img src=".$array[$i]."/>\n";
    }

    for($i=$num_img; $i<$show_img;$i++) {
        echo "<img src=".(count($array) - 1)."/>\n"; 
    }

    //Goes to next page when clicking on next
    if ($index < count($array) - 1) {
        echo '<a href="index.php?start=' . ($index + 1) . '"> next </a> ';
    } else {
        echo '<a href="index.php?start=0"> next </a>';
    }
    ?>

您应该看看这个:

/*数字数组*/
/*$row是您的$array*/
$row=$result->fetch_数组(MYSQLI_NUM);
回声“;
打印(行);
回声“;
这将帮助您获得想要的结果

/* numeric array */
/* $row is your $array */
$row = $result->fetch_array(MYSQLI_NUM);
echo "<pre>";
   print_r($row);
echo "<pre>";