PHP-从查询创建数组

PHP-从查询创建数组,php,arrays,Php,Arrays,我需要用查询中的值填充这个数组 $articles = array( new article("1", "Example item #1", "4.00"), new article("1", "Another thing", "3.50"), new article("1", "Something else", "1.00"), new article("1", "A final item", "4.45"), ); $sql="SELECT quantit

我需要用查询中的值填充这个数组

$articles = array(
    new article("1", "Example item #1", "4.00"),
    new article("1", "Another thing", "3.50"),
    new article("1", "Something else", "1.00"),
    new article("1", "A final item", "4.45"),
); 

$sql="SELECT quantity, desc, curr FROM sales";
我需要一个类的数组中的文章。
我该怎么做?

我不知道你到底想要什么

也许这会给你带来一些价值

foreach($your_query_result AS $key => $value){
    //if your query result is in object
    $articles = array($value->quantity, $value->desc, $value->curr);

    //if your query result is in array
    $articles = array($value['quantity'], $value['desc'], $value['curr']);
} 

试试这个提供的文章是类名

<?php
$dbcon = mysqli_connect("your_host","your_user","your_password","your_db");

// Check connection errors
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

//Run your query using the connection 
$sql="SELECT quantity, desc, curr FROM sales";
$result = mysqli_query($dbcon,$sql);

//Check for any error from the query
if(!$result) echo mysqli_error($dbcon);

//Read the results
$rows = mysql_fetch_assoc($result);

//Now create the array you want using value from each row
$articles = array();
while ($rows){
$articles[] =  new article($rows['quantity'], $rows['desc'], $rows['curr']);
}
?>


请原谅我打字生疏。。。仍在尝试在移动应用程序上执行此操作

您是否可以显示您已经尝试过的内容?发送查询,遍历结果(使用
while
),为每行创建
Article
对象,并将其附加到
$articles
数组中。或者使用一些ORM库。