用 msql fetch 填充 php 数组
Fill php array with msql fetch
我想获取 "till.code" 值并用增量数字索引数组保存它们。
这个想法是我可以用“$array[$variable],$array[$variable]..etc”打印这些值。变量应该是一个数字,1,2,3..
$stmt2=$dbh->prepare("SELECT till.code,shop.description Collate Cyrillic_General_CI_AI as description, count(tra.id) as servicios,ROUND(sum(tra.total_amount),1) as facturacion
FROM [TCPOS4].[dbo].[transactions] as tra, [TCPOS4].[dbo].[tills] as till,[TCPOS4].[dbo].[shops] as shop where tra.till_id=till.id and shop.id=till.shop_id and convert(date,tra.trans_date) = '$name2' and '$usuari'=CAST(LEFT(shop.code,5) AS INT) group by till.code,shop.description order by code;");
$stmt2->execute();
while ($row = $stmt2->fetch()) {
**I have to fill this.**
}
简单的方法,这可能不是最好的方法,但这取决于场景:
$index = 1;
$arr = array();
while ($row = $stmt2->fetch()) {
$arr[ $index ] = $row;
$index++;
}
不确定我是否理解,但也许是这样的。为该列指定别名以简化操作。
$stmt2=$dbh->prepare("SELECT
till.code as 'code',
shop.description Collate Cyrillic_General_CI_AI as 'description',
count(tra.id) as 'servicios',
ROUND(sum(tra.total_amount),1) as 'facturacion'
FROM
[TCPOS4].[dbo].[transactions] as tra,
[TCPOS4].[dbo].[tills] as till,
[TCPOS4].[dbo].[shops] as shop
WHERE tra.till_id=till.id
and shop.id=till.shop_id
and convert(date,tra.trans_date) = '$name2'
and '$usuari'=CAST(LEFT(shop.code,5) AS INT)
GROUP BY till.code,shop.description
ORDER BY code;");
$stmt2->execute();
$output=array();
while( $row = $stmt2->fetch() )$output[]=$row->code;
我想获取 "till.code" 值并用增量数字索引数组保存它们。 这个想法是我可以用“$array[$variable],$array[$variable]..etc”打印这些值。变量应该是一个数字,1,2,3..
$stmt2=$dbh->prepare("SELECT till.code,shop.description Collate Cyrillic_General_CI_AI as description, count(tra.id) as servicios,ROUND(sum(tra.total_amount),1) as facturacion
FROM [TCPOS4].[dbo].[transactions] as tra, [TCPOS4].[dbo].[tills] as till,[TCPOS4].[dbo].[shops] as shop where tra.till_id=till.id and shop.id=till.shop_id and convert(date,tra.trans_date) = '$name2' and '$usuari'=CAST(LEFT(shop.code,5) AS INT) group by till.code,shop.description order by code;");
$stmt2->execute();
while ($row = $stmt2->fetch()) {
**I have to fill this.**
}
简单的方法,这可能不是最好的方法,但这取决于场景:
$index = 1;
$arr = array();
while ($row = $stmt2->fetch()) {
$arr[ $index ] = $row;
$index++;
}
不确定我是否理解,但也许是这样的。为该列指定别名以简化操作。
$stmt2=$dbh->prepare("SELECT
till.code as 'code',
shop.description Collate Cyrillic_General_CI_AI as 'description',
count(tra.id) as 'servicios',
ROUND(sum(tra.total_amount),1) as 'facturacion'
FROM
[TCPOS4].[dbo].[transactions] as tra,
[TCPOS4].[dbo].[tills] as till,
[TCPOS4].[dbo].[shops] as shop
WHERE tra.till_id=till.id
and shop.id=till.shop_id
and convert(date,tra.trans_date) = '$name2'
and '$usuari'=CAST(LEFT(shop.code,5) AS INT)
GROUP BY till.code,shop.description
ORDER BY code;");
$stmt2->execute();
$output=array();
while( $row = $stmt2->fetch() )$output[]=$row->code;