尝试获取数据 codeigniter 的问题
Issue trying to fetch data codeigniter
我在视图文件中遇到了这个错误(还有很多关于索引 ID、用户名、姓名、姓氏、密码、类型、状态、日期的错误):
https://i.gyazo.com/d8bda30b1fafce47ed2125d590c5b4e4.png
我只显示包含 "simple" 用户 ("type = 1") 的行,这些行存储在 table "usuarios"
中
Table "usuarios".
"usuarios" includes:(id,username,name,lastname,password,type,status,date).
当我以管理员身份进入系统时,程序必须显示 table,其中所有 "simple" 用户存储在 table "usuarios".
我需要这样的东西:
https://i.gyazo.com/36f11b368a339964f1b734cea0177734.png
这是我的代码:
我的查看文件("user_view"):
<table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
<thead>
<th>id</th>
<th>User</th>
<th>Name</th>
<th>Lastname</th>
<th>Password</th>
<th>Type</th>
<th>Status</th>
<th>Date</th>
</thead>
<tbody>
<?php
if (count($records) > 0 && $records != false)
{
foreach($records as $record) {
echo "<tr>
<td>".$records['id']."</td>
<td>".$records['username']."</td>
<td>".$records['name']."</td>
<td>".$records['lastname']."</td>
<td>".$records['password']."</td>
<td>".$records['type']."</td>
<td>".$records['status']."</td>
<td>".$records['date']."</td>
</tr>";
}
}
?>
</tbody>
</body>
</html>
我的模型函数:
public function getINFOUSER(){
$query = $this->db->get_where('usuarios',array('type'=>1));
if ($query->num_rows() > 0 ) {
$result = $query->result_array();
}
return $result;
}
现在不知道怎么办:S
是记录,不是foreach里面的记录:
foreach($records as $record) {
echo "<tr>
<td>".$record['id']."</td>
<td>".$record['username']."</td>
<td>".$record['name']."</td>
<td>".$record['lastname']."</td>
<td>".$record['password']."</td>
<td>".$record['type']."</td>
<td>".$record['status']."</td>
<td>".$record['date']."</td>
</tr>";
}
希望这会奏效。
您的代码中有一些错误。你写错了变量名。我刚刚更正了它。
<?php
if (count($records) > 0 && $records != false)
{
foreach($records as $record) {
echo "<tr>
<td>".$record['id']."</td>
<td>".$record['username']."</td>
<td>".$record['name']."</td>
<td>".$record['lastname']."</td>
<td>".$record['password']."</td>
<td>".$record['type']."</td>
<td>".$record['status']."</td>
<td>".$record['date']."</td>
</tr>";
}
}
?>
我在视图文件中遇到了这个错误(还有很多关于索引 ID、用户名、姓名、姓氏、密码、类型、状态、日期的错误):
https://i.gyazo.com/d8bda30b1fafce47ed2125d590c5b4e4.png
我只显示包含 "simple" 用户 ("type = 1") 的行,这些行存储在 table "usuarios"
中Table "usuarios".
"usuarios" includes:(id,username,name,lastname,password,type,status,date).
当我以管理员身份进入系统时,程序必须显示 table,其中所有 "simple" 用户存储在 table "usuarios".
我需要这样的东西:
https://i.gyazo.com/36f11b368a339964f1b734cea0177734.png
这是我的代码:
我的查看文件("user_view"):
<table class="table table-hover" align="center" border="1" cellspacing="0" cellpadding="0" width="700" id="tabla_busqueda">
<thead>
<th>id</th>
<th>User</th>
<th>Name</th>
<th>Lastname</th>
<th>Password</th>
<th>Type</th>
<th>Status</th>
<th>Date</th>
</thead>
<tbody>
<?php
if (count($records) > 0 && $records != false)
{
foreach($records as $record) {
echo "<tr>
<td>".$records['id']."</td>
<td>".$records['username']."</td>
<td>".$records['name']."</td>
<td>".$records['lastname']."</td>
<td>".$records['password']."</td>
<td>".$records['type']."</td>
<td>".$records['status']."</td>
<td>".$records['date']."</td>
</tr>";
}
}
?>
</tbody>
</body>
</html>
我的模型函数:
public function getINFOUSER(){
$query = $this->db->get_where('usuarios',array('type'=>1));
if ($query->num_rows() > 0 ) {
$result = $query->result_array();
}
return $result;
}
现在不知道怎么办:S
是记录,不是foreach里面的记录:
foreach($records as $record) {
echo "<tr>
<td>".$record['id']."</td>
<td>".$record['username']."</td>
<td>".$record['name']."</td>
<td>".$record['lastname']."</td>
<td>".$record['password']."</td>
<td>".$record['type']."</td>
<td>".$record['status']."</td>
<td>".$record['date']."</td>
</tr>";
}
希望这会奏效。
您的代码中有一些错误。你写错了变量名。我刚刚更正了它。
<?php
if (count($records) > 0 && $records != false)
{
foreach($records as $record) {
echo "<tr>
<td>".$record['id']."</td>
<td>".$record['username']."</td>
<td>".$record['name']."</td>
<td>".$record['lastname']."</td>
<td>".$record['password']."</td>
<td>".$record['type']."</td>
<td>".$record['status']."</td>
<td>".$record['date']."</td>
</tr>";
}
}
?>