简体   繁体   English

在jpGraph的数据库显示中需要换行

[英]Need line breaks in database display for jpGraph

I'm learning how to use jpGraph to display bar graphs. 我正在学习如何使用jpGraph显示条形图。 The instructions explain how to create a .txt file with the following data: 这些说明说明了如何使用以下数据创建.txt文件:

1700.5   5.0  
1701.5  110.0  
1702.5  16.0  
1703.5  23.0  

I discovered that it still works if I change the extension to .php. 我发现如果将扩展名更改为.php,它仍然可以工作。 But rather than use a static file, I want to figure out how to display data from a database table. 但是,我不想使用静态文件,而是想出如何显示数据库表中的数据。 Specifically, I want to display dates and test scores, like this: 具体来说,我想显示日期和测试成绩,如下所示:

2015-01-05  10
2015-01-05  50
2015-01-21  80

So I replaced the static data with a database query, followed by this code... 所以我用数据库查询替换了静态数据,然后加上了这段代码...

while ($row = $stm->fetch())
{
 $Test_Score = $row['Test_Score'];
 $Test_Date = $row['Test_Date'];

 $Results[] = ''.$Test_Date.'  '.$Test_Score.'';
}

echo join ($Results, '');

The problem is that this displays something like this... 问题是,这会显示类似这样的内容...

2015-01-05  102015-01-05  502015-01-21  80

Adding a break doesn't help, apparently because it isn't compatible with jpGraph's code... 添加中断并没有帮助,显然是因为它与jpGraph的代码不兼容...

$Results[] = ''.$Test_Date.'  '.$Test_Score.'<br>';

So I'm trying to figure out an alternative way to insert line breaks after each row of code. 因此,我试图找出在每行代码之后插入换行符的替代方法。 I'm on a Mac, so I think I'm supposed to use /r/n, but I've also tried /r and /n, enclosed in both double quotes and single quotes. 我在Mac上,因此我认为应该使用/ r / n,但我也尝试过/ r和/ n,并用双引号和单引号括起来。

What's the magic formula? 什么是魔术公式?

Try it: 试试吧:

$lines = implode(PHP_EOL,$Results); // equal join(PHP_EOL,$Results);

Constant PHP_EOL automatically set correct line-break of current OS. 常量PHP_EOL自动设置当前操作系统的正确换行符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM