[eluser]\/ertigo[/eluser]
I am new to PHP and CodeIgniter: I am following along with the NETTUTS video tutorials, but am stumped as how to access database records with spaces in them. The error I am getting is "PHP Parse error: syntax error, unexpected T_VARIABLE".
I am looking to access the "First Name" and "Last Name" records.
Here is the code from the controller:
Code:
<? class Personnel extends Controller {
function __constructer() {
parent::Controller();
}
function index() {
$this->load->model('personnel_model');
$data['title']="Personnel Records";
$this->load->view('header',$data);
$this->load->view('toc');
$data['records']=$this->personnel_model->GetList();
$this->load->view('personnel',$data);
$data['url']=current_url();
$this->load->view('footer',$data);
}
}
Here is the model code:
Code:
<? class Personnel_model extends Model {
function getList() {
$q = $this->db->query("SELECT Department,`First Name`,`Last Name`,Extension from Users" ) ;
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
Here is the view:
Code:
<table><tr><th>Name</th><th>Department</th><th>Extension</th></tr>
<? foreach($records as $row) :?>
<tr><td><!--?=$row[Last Name] ?>, <!--?=$row->"First Name"--></td>
<td><?=$row->Department?></td><td><?=$row->Extension?></td>
<? endforeach; ?>
</table>
<? print_r ($records); ?><br><br>
<? var_dump ($records); ?>
And finally, here is the output I am getting from print_r() and var_dump():
Code:
Array ( [0] => stdClass Object ( [Department] => 1 [First Name] => Me [Last Name] => Test [Extension] => 283 ) )
array(1) { [0]=> object(stdClass)#14 (4) { ["Department"]=> string(1) "1" ["First Name"]=> string(3) "Me" ["Last Name"]=> string(4) "Test" ["Extension"]=> string(3) "283" } }