Variable contains data but it is not printed out - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, June 20, 2022

Variable contains data but it is not printed out

I am fetching data from database and trying to display it in a view but it does not work. However, print_r outputs the data successfully.

Model:

<?php
class Usermodel Extends CI_model{
    public function getUserdata() 
    {
        $this->load->database();
        // $q=$this->db->select('name');
        $q=$this->db->get('user');
        return $q->result_array();
    }
}
?>

Controller:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Users extends CI_controller{
    public function User(){
        $this->load->model('Usermodel');
        $data['users']=$this->Usermodel->getUserdata();
        $this->load->view('Users/userlist',$data);

    }
}
?>

View:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>User Details</title>
</head>
<body>
    <br>
    <?php print_r($users); ?>
    <h1>User Account Details</h1>
    <tr>
        <td>First Name</td>
        <td>Account No</td>
    </tr>
    <?php foreach($users as $users): ?>
    <tr>
        <td><?php $users['name']; ?></td>
        <td><?php $users['accountnumber']; ?></td>
    </tr>
    <?php endforeach ?>
</body>
</html>


source https://stackoverflow.com/questions/72654650/variable-contains-data-but-it-is-not-printed-out

No comments:

Post a Comment