php - 将 MySQL 列存储到数组中,然后在 PHP 中打印

标签 php mysql arrays database

我正在尝试将数据库中名为 images 的表中名为 imgPath 的列存储到 PHP 数组中。然后我想把它打印出来,这样我就可以看到它起作用了。您可以在下面看到表格的样子:

From the table **images**

下面是我用来不成功的代码,哈哈:

$db = mysqli_connect('localhost', 'userdatabase', 'PASSData', 'sftdatabase');
$result = mysqli_query($db,"SELECT imgPath FROM images"); 

$result_array = array();

while($row = mysql_fetch_assoc($result))
{
    $result_array[] = $row['imgPath'];
}
print_r($result_array);

我在创建数组之前尝试使用 print_r($result);,我得到:

This

如何获取路径? (示例: img/art/10/download.jpg)

最佳答案

简单的错误,

改变,

while($row = mysql_fetch_assoc($result))

为了,

while($row = mysqli_fetch_assoc($result))

请注意 mysqlii 在第一个中丢失。

关于php - 将 MySQL 列存储到数组中,然后在 PHP 中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49656272/

相关文章:

php - Mysql批量插入不插入所有数据

c++ - 在优先队列中出列

Java : Difficulties trying to store data from MySQL DB into a two-dimensional array of Strings

php - codeigniter 2.0.3- fatal error

php - 如何将数据从 MySQL 传递到 Google map

php - 图像不水平显示

php - 在现有语句中添加联接

mysql - 如何过滤特殊产品订单的行?

php - 如何在sql中一起使用like和between?

arrays - Swift 3 - 两个字典数组之间的区别