- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经对这个错误进行了非常彻底的搜索,虽然我找到了很多关于“确保您正在传递数组或 SQL 查询”的一般性答案,但我认为我可能需要每个 CodeIgniter 库的更具体的帮助。
我有一个 View ,它只是应该创建一个查询(或数组)并生成一个表。
(最终,查询将从模型中发生,表生成将成为我的 Controller 中的一个函数,因此我可以在其他 View 中重用它,但我只是从基本的屏幕回显开始)
View 是这样设置的:
<div class="span4 well well-small">
<h4>Requests:</h4>
<?php
$this->table->set_heading('ID', 'Request', 'User', 'Date');
$query = array('id'=>'123', 'request'=>'FARTS', 'user'=>'Steve', 'date'=>'Today'); //$this->db->select('user_id', 'password', 'user_name', 'company_id')->from('users');
echo $this->table->generate($query);
?>
<h4>In this div:</h4>
<p>we will display some information about recent requests. It will show a small table with Request ID, Request Name, and Date Requested headers.</p>
</div>
这将打印一个包含 4 个 PHP 错误框的框,内容为:
遇到 PHP 错误
严重性:警告
消息:为 foreach() 提供的参数无效
文件名:libraries/Table.php
行号:198
当我检查 Table.php 库中的第 198 行时,它需要一个数组(关联或非关联),或来自数据库的查询。我试图传递一个非关联数组、一个关联数组和一个数据库查询,所有这些都会产生同样的错误。
而且,您不必翻阅 CI,这里是抛出错误的函数:
function _prep_args($args)
{
// If there is no $args[0], skip this and treat as an associative array
// This can happen if there is only a single key, for example this is passed to table->generate
// array(array('foo'=>'bar'))
if (isset($args[0]) AND (count($args) == 1 && is_array($args[0])))
{
// args sent as indexed array
if ( ! isset($args[0]['data']))
{
foreach ($args[0] as $key => $val)
{
if (is_array($val) && isset($val['data']))
{
$args[$key] = $val;
}
else
{
$args[$key] = array('data' => $val);
}
}
}
}
else
{
foreach ($args as $key => $val)
{
if ( ! is_array($val))
{
$args[$key] = array('data' => $val);
}
}
}
return $args;
}
最佳答案
将您的 $query 变量更改为如下所示:
$query = array(array('id'=>'123', 'request'=>'FARTS', 'user'=>'Steve', 'date'=>'Today'));
该方法需要一个数组数组,即使没有特定的键=>值对也是如此。
$query = array(array('123','FARTS','Steve', 'Today'));
本质上,当您使用 CI 的数据库库时,这也是您的数据库查询应该返回的内容。
就个人而言,除非您打算直接使用来自数据库查询的数据,否则我会使用:
$this->table->add_row('123','FARTS','Steve', 'Today');
-OR-
$this->table->add_row(array('ID'=>'hello','class'=>'Today','data'=>'Displayed Text'));
就您的数据库查询遇到相同的错误而言,我会三次检查您实际从所述查询中收到的输出类型。
希望对你有帮助
关于php - CodeIgniter:PHP 错误:Table.php 中的 foreach() 中的参数无效:第 198 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14241976/
这个问题在这里已经有了答案: What is the best way to parse html in C#? [closed] (15 个答案) 关闭 3 年前。 string input =
为什么 wrapper #4 没有继承其父表容器的高度?表格嵌套在一个显示 block 包装器中,每个嵌套的div是显示表格,每个表格继承到最里面的一个。是什么原因造成的,我该如何解决? jsfidd
我正在使用带有 Bootstrap 的自定义 css 作为外边框。但顶部边框不可见,除非我将其大小设置为 2 px。 我该如何解决这个问题? HTML #name 1.one 2.two 3.thr
我正在逻辑层面上设计一个数据库,以便稍后将其传递给程序员来交付。我只是粗略地了解它们的工作原理,所以我很难简洁地表达我的问题。这是我的问题: 我有一个名为 MEANINGS 的表。 我有一个名为 WO
在 Laravel 上,我们可以使用 DB::table('table')->get(); 或使用 model::('table')->all() 进行访问;我的问题是它们之间有什么区别? 谢谢。 最
我试图从以下内容中抓取 URL从 WorldOMeter 获取 CoVid 数据,在此页面上存在一个表,id 为:main_table_countries_today其中包含我希望收集的 15x225
这是我的图表数据库:/image/CGAwh.png 我用 SEQUELIZE 制作了我的数据库模型: 型号:级别 module.exports = (sequelize, DataTypes) =>
我真的不明白为什么我的代码不能按预期工作。当我将鼠标悬停在表格的每一行上时,我想显示一个图像(来 self 之前加载的 JSON)。每个图像根据行的不同而不同,我想将它们显示在表格之外的另一个元素中。
假设我的数据库中有一张地铁 map ,其中每条线路的每个站点都是一行。如果我想知道我的线路在哪里互连: mysql> SELECT LineA.stop_id FROM LineA, LineB WH
我最近经常使用这些属性,尤其是 display: table-cell。它在现代浏览器中得到了很好的支持,并且它对某些网格有很多好处,并且可以非常轻松地对齐内容,而无需棘手的标记。但在过去的几天里,我
在 CSS 中,我可以这样做: http://s1.ipicture.ru/uploads/20120612/Uk1Z8iZ1.png http://s1.ipicture.ru/uploads/20
问题作为标题,我正在学习sparkSQL,但我无法很好地理解它们之间的区别。谢谢。 最佳答案 spark.table之间没有区别& spark.read.table功能。 内部 spark.read.
我正在尝试根据 this answer 删除表上的非空约束.但是,它似乎没有在 sqlite_sequence 中创建条目。这样做之后,即使我可以在使用测试表时让它正常工作。 有趣的是,如果我备份我的
var otable = new sap.m.Table();//here table is created //here multiple header I'm trying to create t
下面两种方法有什么区别: 内存 性能 答: select table.id from table B: select a.id from table a 谢谢(抱歉,如果我的问题重复)。 最佳答案 完
我尝试在表格后添加点,方法是使用 table::after 选择器创建一个点元素并使用 margin: 5px auto 5px auto; 将其居中。它有效,但似乎在第一个表格列之后添加了点,而不是
我正在设计一个可以标记任何内容的数据库,我可能希望能够选择带有特定标记的所有内容。 我正在为以下两个选项而苦苦挣扎,希望得到一些建议。如果有更好的方法请告诉我。 选项A 多个“多对多”连接表。 tag
"center" div 中的下表元素导致 "left" div 中的内容从顶部偏移几个像素(在我的浏览器中为 8 ).在表格之前添加一些文本可消除此偏移量。 为什么?如何在不要求在我的表格前添加“虚
我是一名优秀的程序员,十分优秀!