而mysql_fetch_assoc到数组

时间:2018-01-10 18:48:40

标签: php mysql

我正在尝试将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 个答案:

答案 0 :(得分:0)

您应该使用PDO连接到数据库,因为它更安全:http://php.net/manual/en/book.pdo.php

这些教程非常适合关注:http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers http://crewow.com/PHP-MySQL-Simple-Select-using-PDO-in-Bootstrap.php

我认为你需要这样的东西:http://php.net/manual/en/pdostatement.fetchall.php

// mymodule.js
exports.myfunc = function(ele){
  if(ele instanceof d3.selection){
    // do something
  } else {
    // throw error
  }
}

// main.js    
var d3 = require('d3')
mymodule = require('mymodule');
var ele = d3.selection.select('#myElement');
mymodule.myfunc(ele);

结果如下:

// mymodule.js
exports.myfunc = function(ele){
  if(ele instanceof d3.selection){
    // do something
  } else {
    // throw error
  }
}

// main.js    
var d3Selection = require('d3-selection')
mymodule = require('mymodule');
var ele = d3Selection.select('#myElement');
mymodule.myfunc(ele);

答案 1 :(得分:0)

您可以使用array_push()

while($row = mysql_fetch_assoc($shots)) {
   array_push($a, "http://www.example.com/images/item/".$row['name']."_thb.".$row['ext']);
}

print_r($a);

我不建议使用mysql_,因为它已被弃用

相关问题