-4

有人可以解释这个脚本执行时到底发生了什么。它就像一个魅力,但我不知道它究竟做了什么而感到不满意。

基本上我有一个带有以下字段的 sql 表 [images]

  • 文件名
  • 照料
  • 网址

我想做的是获取 [URL] 的所有值并将其放在一个数组中

为了实现这一点,我习惯于遵循我在 stackoverflow 上找到的脚本

$images = mysql_query("Select URL from images where Category = 'Management' ");
$imagerow = Array();

while ( $row = mysql_fetch_assoc($images) )
{
$imagerow[] = $row['URL'];
}

echo $imagerow[0] ;

该脚本的工作原理就像一个魅力,但是对于 php 和 mysql 来说,我发现很难理解到底发生了什么。如果有人用简单的话解释会发生什么,我会喜欢的。

4

1 回答 1

1

这个问题并不真正属于这里,但为了在不打扰版主的情况下结束问题,我会回答它。

// mysql query is executed
$images = mysql_query("Select URL from images where Category = 'Management' ");

// empty array initialized
$imagerow = Array();

// while there are results of the executed mysql query
while ( $row = mysql_fetch_assoc($images) )
{
    // create a new element in $imagerow array and put url of the image there
    $imagerow[] = $row['URL'];
}

// output first element of the array we have just filled
echo $imagerow[0] ;
于 2013-03-12T06:10:13.560 回答