【问题标题】:How to add title in JPGraph from mysql database如何从 mysql 数据库在 JPGraph 中添加标题
【发布时间】:2017-02-19 16:54:25
【问题描述】:

我使用 jpgraph 生成图表。我成功地从数据库中获取了绘图的数据,我希望标题也从数据库中获取。我已经在使用这个脚本了

$sql = $this->db->select("title from table")->get()->first_row();
$title = $sql->title;
$graph->title->Set($title);

但这不起作用。谁能解决这个问题?谢谢

【问题讨论】:

  • 你检查答案了吗?
  • 是的,但它也没有工作
  • chk 结果echo $title;exit; chk r u 在此行之前获得标题$graph->title->Set($title);
  • 致命错误:调用数组上的成员函数 first_row()
  • 我在我的问题中检查了sript的结果,结果是正确的但不能包含在图表标题中

标签: php mysql codeigniter jpgraph


【解决方案1】:

这将有助于获取 first_row 和字段:

$this->db->select('title');  // your column
$this->db->from('table');   // your table
$result = $this->db->get()->result(); // get result
$title = $result->first_row()->title; // get ist row using first_row with your field name
$graph->title->Set($title); // as you are using for graph

还要注意,在 CI 函数 row() 中,还会以对象形式返回查询的第一行。

来自手册:

您可以使用 这些变化:

$row = $query->first_row()
$row = $query->last_row()
$row = $query->next_row()
$row = $query->previous_row()

或者如果你想在数组而不是对象中打印结果,那么你可以使用单词“array”作为参数,例如:

$query->first_row(‘array’) 

您也可以按照 CI 手册更好地理解:http://www.codeigniter.com/userguide3/database/results.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多