Welcome Guest, Not a member yet? Register   Sign In
Echo Array Elements?
#1

[eluser]ShawnMA[/eluser]
***EDITED***
I got it working using:

Code:
<?php foreach ($featured as $row):?>
<h4> &lt;?php echo $row->event_name;?&gt;</h4>
&lt;?php endforeach; ?&gt;

Is it really necessary to use a foreach, when there will always only be one row returned?

In my controller, I make a call to my model to query the db for a record and all of its field:

Code:
$data['featured'] = $this->event_model->getFeaturedEventByMetro( $code );

The query does return data, I've confirmed this, but when attempting to access the individual elements via my view, I keep getting:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: event_name
Filename: views/home.php
Line Number: 63


In my view I have the folllowing:
Code:
<h4>&lt;?php echo $featured['event_name']; ?&gt;</h4>

event_name is a field in the returned row, and it does have a value, I'm thrown for what I'm doing wrong. All help is greatly appreciated.
#2

[eluser]Wondering Coder[/eluser]
Since you didn't show your model, if you only want to return 1 record you could use row() and if there's more than 1 record to show result(). Read the user guide.

now for your problem try this in your view.
Code:
&lt;?=$featured->event_name;?&gt; //assuming your using return row() object




Theme © iAndrew 2016 - Forum software by © MyBB