Skip to content

Commit

Permalink
playing with database
Browse files Browse the repository at this point in the history
  • Loading branch information
Shemona Singh authored and Shemona Singh committed Nov 30, 2017
1 parent 593d80e commit 62115f0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
18 changes: 18 additions & 0 deletions www/application/controllers/All_Tweets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class All_Tweets extends CI_Controller {

function __Construct(){
parent::__Construct ();
$this->load->database(); // load database
$this->load->model('All_Tweets_Model'); // load model
$this->output->enable_profiler(TRUE);
}

public function index() {
$this->data['posts'] = $this->All_Tweets_Model->getPosts(); // calling Post model method getPosts()
$this->load->view('posts_view', $this->data); // load the view file , we are passing $data array to view file
}

}
13 changes: 13 additions & 0 deletions www/application/models/All_Tweets_Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
class PostModel extends CI_Model {

function getPosts(){
$this->db->select("first_name,last_name,username");
$this->db->from('Users');
$query = $this->db->get();
var_dump($query->result_array());
// return $query->result();
}

}
?>
32 changes: 31 additions & 1 deletion www/application/views/pages/home.php
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
<?php echo "Tweets!"; ?>
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>All Tweets</title>
<style type="text/css">

</style>
</head>
<body>

<h4>Output Data</h4>
<table>
<tr>
<td><strong>Post Id</strong></td>
<td><strong>Post Title</strong></td>
</tr>
<?php foreach($posts as $post){?>
<tr>
<td><?php echo $post->first_name;?></td>
<td><?php echo $post->last_name;?></td>
</tr>
<?php }?>
</table>

</div>

</body>
</html>
1 change: 1 addition & 0 deletions www/application/views/templates/header.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html>
<head>
<title>Twitter</title>
<?php $this->load->helper('url'); ?>
<link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>" />
</head>
<body>
Expand Down

0 comments on commit 62115f0

Please sign in to comment.