[eluser]swgj19[/eluser]
Codeigniter Vs. 2.0
Oh right. I basically queried my database in my model. Then in my controller I called my model. And then I called the string as $row in a foreach in my view. I am getting that basic old error and I cannot figure out why. I commented out the foreach on my view and the error goes away. So I know where the error is caused, but cannot figure out how to keep my foreach loop in my view without the error. Thanks guys..
Here is the full error:
Parse error: syntax error, unexpected $end in /home/content/70/6930870/html/tt/application/views/logged_in_area.php on line 28
Here is my model:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Membership_model extends CI_Model {
function validate()
{
$this->db->where('username', $this->input->post('username')); //validate username
$this->db->where('password', md5($this->input->post('password'))); //validate password
$query = $this->db->get('membership'); //get db table
if($query->num_rows == 1) //Make sure data in table exist
{
return true; //if data in table, then return results
}
}
function create_member()
{
$new_member_insert_data = array( //if validation passed (line 57 controller/login.php), post array data to db
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'email_address' => $this->input->post('email_address'),
'username' => $this->input->post('username'),
'password' => md5($this->input->post('password')) //make sure password is md5 or same in db
);
$insert = $this->db->insert('membership', $new_member_insert_data); //insert (insert is new_member_insert_data array) into membership table
return $insert;
}
function retrieve()
{
$q = $this->db->get('membership');
$this->db->where('email_address', $this->input->post('email_address')); //validate username
if($q->num_rows() > 0) {
foreach($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
/*if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row->row;
}
return $data;
}*/
Here is my controller
Code:
<?php
class Site extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->is_logged_in();
}
function members_area()
{
$this->load->model('Membership_model');
$data['records'] = $this->Membership_model->retrieve();
//$data['t'] = $this->db->get('membership','first_name'); //Need to have result before converting to a string.
$this->load->view('logged_in_area', $data);
}
function account()
{
redirect('site/members_area');
}
function another_page() // just for sample
{
echo 'good. you\'re logged in.';
}
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true)
{
echo 'You don\'t have permission to access this page.';
echo anchor('login/index', 'Login');
die();
//$this->load->view('login_form');
}
}
}
Here is my view
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
</head>
<body>
<h2>Welcome Back, <?php echo $this->session->userdata('username'); ?>!</h2>
<p>If you are a member you can stay. If not, then get out!</p>
<h4>
<?php echo anchor('site/members_area','Profile');?> |
<?php echo anchor('login/logout', 'Logout');?> |
<?php echo anchor('site/account', 'Account');?>
</h4>
<?php
foreach($records as $row):
echo $row->first_name;
?>
</body>
</html>