我正在尝试将while转换为数组
我有mysql查询:
$shots = mysql_query("SELECT name, ext FROM my_images WHERE item_id=$idnumber") or die(mysql_error());
while($row = mysql_fetch_assoc($shots)) {
echo "http://www.example.com/images/item/";
echo $row["name"];
echo '_thb.';
echo $row["ext"];
echo '<br>';
}
它给了我:
http://www.example.com/images/item/image1_thb.jpg
http://www.example.com/images/item/image2_thb.jpg
http://www.example.com/images/item/image3_thb.jpg
所以它工作得很好。
我需要把它放到:
$files_to_zip = array(
'http://www.example.com/images/item/image1_thb.jpg',
'http://www.example.com/images/item/image2_thb.jpg',
'http://www.example.com/images/item/image3_thb.jpg',
);
我该怎么做?谢谢
2条答案
按热度按时间a5g8bdjr1#
你可以用
array_push()
.我不建议使用
mysql_
因为它被弃用了ukqbszuj2#
您应该使用pdo连接到数据库,因为它更安全:http://php.net/manual/en/book.pdo.php
以下教程非常好:http://wiki.hashphp.org/pdo_tutorial_for_mysql_developershttphttp://crewow.com/php-mysql-simple-select-using-pdo-in-bootstrap.php
我想你需要这样的东西:http://php.net/manual/en/pdostatement.fetchall.php
结果如下: