Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用多个MySql列创建内联数组_Php_Mysql_Arrays - Fatal编程技术网

Php 使用多个MySql列创建内联数组

Php 使用多个MySql列创建内联数组,php,mysql,arrays,Php,Mysql,Arrays,因此,我有一个MySQL查询,它返回许多结果(在本例中,产品使用不同的货币)。它们在表中显示如下: Product Name | Euros | Dollars | GBP | Stock? _______________________________________________ Acme Produce | 34.00 | 52.00 | 30.00 | "In Stock" MoreProducts | 153.00 | 160.00 | 144.

因此,我有一个MySQL查询,它返回许多结果(在本例中,产品使用不同的货币)。它们在表中显示如下:

Product Name  |  Euros  |  Dollars  |  GBP  |  Stock?
_______________________________________________
Acme Produce  |  34.00  |  52.00  |  30.00  |  "In Stock"
MoreProducts  | 153.00  | 160.00  | 144.00  |  "In Stock"
$lines = array();
foreach ($row_productDetails) {
    $lines[] = "'{$row_productDetails['NAME']}', currently selling for E{$row_productDetails['EUR']}, ${$row_productDetails['USD']}, £{$row_productDetails['GBP']} {$row_productDetails['InStock']}";
}

var_dump(implode(", and "));
我希望能够在一行中用PHP全部打印出来(我知道,当表中有信息时听起来很傻,但这是有原因的),就像这样

“目前,您有许多产品,包括‘Acme Product’。” 售价为E34.00美元、52.00美元、30.00英镑库存和“更多产品”, 目前售价为E153.00美元,160.00美元,144.00英镑,您可以 “好久没看了”

我怎么可能为这个构造一个字符串

我使用以下方法从MySQL获得产品:

$query_productDetails = sprintf("SELECT * FROM ProductsView")
$query_limit_productDetails = sprintf("%s LIMIT %d, %d", $query_productDetails, $startRow_productDetails, $maxRows_productDetails);
$productDetails = mysql_query($query_limit_productDetails, $Products) or die(mysql_error());
$row_productDetails = mysql_fetch_assoc($productDetails);

if (isset($_GET['totalRows_productDetails'])) {
  $totalRows_productDetails = $_GET['totalRows_productDetails'];
} else {
  $all_productDetails = mysql_query($query_productDetails);
  $totalRows_productDetails = mysql_num_rows($all_productDetails);
}
然后获取
中的各个列(例如)


如何将这些信息放入数组中,以便以所需的格式将其组合在一起?

您不能这样做吗:

Product Name  |  Euros  |  Dollars  |  GBP  |  Stock?
_______________________________________________
Acme Produce  |  34.00  |  52.00  |  30.00  |  "In Stock"
MoreProducts  | 153.00  | 160.00  | 144.00  |  "In Stock"
$lines = array();
foreach ($row_productDetails) {
    $lines[] = "'{$row_productDetails['NAME']}', currently selling for E{$row_productDetails['EUR']}, ${$row_productDetails['USD']}, £{$row_productDetails['GBP']} {$row_productDetails['InStock']}";
}

var_dump(implode(", and "));

离题,但将价格作为不同货币的固定值而不是使用利率是否明智?这是一个很好的观点-但这种方法有一个无聊的合同原因。实际上。。。那太好了!我一直在尝试一系列奇怪的内爆和爆炸。。。但这是甜蜜的!谢谢你的回答!还有一件事——第二行似乎有语法错误——这里是否缺少括号?它是作为示例编写的,您必须遍历您的行