在图形的 fpdf 数据中插入数组
inserting an array in a fpdf data for graph
我必须在图形数据中放置一个数组
这是原始格式
$data = array( "DATA_1title" => DATA1, "DATA_2title" => DATA2);
这是 php
的声明
$sqlb = "SELECT date_format(datesales, '%M %D %Y') as datesales,
sum(amount) as amount from sales
where date(datesales) <= curdate() and
date(datesales) >= curdate() - interval 6 day
group by DATE_FORMAT(datesales, '%M %D %Y')";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc())
{
$datesales = $rowb['datesales'];
$amount = $rowb['amount'];
}
我试过这个代码
$sqlb = "SELECT date_format(datesales, '%M %D %Y') as datesales,
sum(amount) as amount from sales
where date(datesales) <= curdate() and
date(datesales) >= curdate() - interval 6 day
group by DATE_FORMAT(datesales, '%M %D %Y')";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc())
{
$datesales=$rowb['datesales'];
$amount=$rowb['amount'];
$data = array( "$datesales" => $amount,);
}
但它只显示一个值
而不是一组值
我也试过这个
$sqlb = "SELECT date_format(datesales, '%M %D %Y') as datesales,
sum(amount) as amount from sales
where date(datesales) <= curdate() and
date(datesales) >= curdate() - interval 6 day
group by DATE_FORMAT(datesales, '%M %D %Y')";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc())
{
$data = array( "$rowb['datesales']" => $rowb['amount'],);
}
但我得到了相同的结果
我想要的是,不是每次都手动输入键和值,而是可以使用我所做的 sql 语句将其从数据库中拉出。
Instead of this
$data = array( "DATA_1title" => DATA1, "DATA_2title" => DATA2);
I want it to be like this
**SQL STATEMENT HERE**
$data = array( "$datetimes" => $amount);
$datetimes refers to the alias in the sql statement which is an array
so is $amount
您可以简单地使用一个值作为键,另一个作为值。例如:
// instead of your while loop
foreach($resultb as $rowb) {
$data[$rowb['datesales']] = $rowb['amount'];
}
我必须在图形数据中放置一个数组 这是原始格式
$data = array( "DATA_1title" => DATA1, "DATA_2title" => DATA2);
这是 php
的声明 $sqlb = "SELECT date_format(datesales, '%M %D %Y') as datesales,
sum(amount) as amount from sales
where date(datesales) <= curdate() and
date(datesales) >= curdate() - interval 6 day
group by DATE_FORMAT(datesales, '%M %D %Y')";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc())
{
$datesales = $rowb['datesales'];
$amount = $rowb['amount'];
}
我试过这个代码
$sqlb = "SELECT date_format(datesales, '%M %D %Y') as datesales,
sum(amount) as amount from sales
where date(datesales) <= curdate() and
date(datesales) >= curdate() - interval 6 day
group by DATE_FORMAT(datesales, '%M %D %Y')";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc())
{
$datesales=$rowb['datesales'];
$amount=$rowb['amount'];
$data = array( "$datesales" => $amount,);
}
但它只显示一个值 而不是一组值 我也试过这个
$sqlb = "SELECT date_format(datesales, '%M %D %Y') as datesales,
sum(amount) as amount from sales
where date(datesales) <= curdate() and
date(datesales) >= curdate() - interval 6 day
group by DATE_FORMAT(datesales, '%M %D %Y')";
$resultb = $conn->query($sqlb);
while($rowb = $resultb->fetch_assoc())
{
$data = array( "$rowb['datesales']" => $rowb['amount'],);
}
但我得到了相同的结果 我想要的是,不是每次都手动输入键和值,而是可以使用我所做的 sql 语句将其从数据库中拉出。
Instead of this
$data = array( "DATA_1title" => DATA1, "DATA_2title" => DATA2);
I want it to be like this
**SQL STATEMENT HERE**
$data = array( "$datetimes" => $amount);
$datetimes refers to the alias in the sql statement which is an array
so is $amount
您可以简单地使用一个值作为键,另一个作为值。例如:
// instead of your while loop
foreach($resultb as $rowb) {
$data[$rowb['datesales']] = $rowb['amount'];
}