Issue trying to fetch data codeigniter

筅森魡賤 提交于 2020-01-07 04:47:06

问题


I got this errors in the view file (and so many more about the indexes id,username, name, lastname, password, type, status, date):

https://i.gyazo.com/d8bda30b1fafce47ed2125d590c5b4e4.png

I gotta show ONLY the rows that contain "simple" users ("type = 1") which are stored inside the table "usuarios"

Table "usuarios".

"usuarios" includes:(id,username,name,lastname,password,type,status,date).

When i enter the system as an ADMIN the program must show a table with all the "simple" users stored in the table "usuarios".

I need something like this:

https://i.gyazo.com/36f11b368a339964f1b734cea0177734.png

This is my code:

My view file ("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>

My model function:

    public function getINFOUSER(){

    $query = $this->db->get_where('usuarios',array('type'=>1));
    if ($query->num_rows() > 0 ) {
        $result = $query->result_array();
    }

    return $result; 

}

Do not know what to do now :S


回答1:


It is record, not records inside 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>"; 

}

Hope this will work.




回答2:


There is some error in your code. you have written wrong variable name. I just corrected it.

 <?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>"; 

    }
    }

    ?>


来源:https://stackoverflow.com/questions/43327024/issue-trying-to-fetch-data-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!