Solved

Codeigniter

Posted on 2012-03-30
4
347 Views
Last Modified: 2012-03-30
Hi i begin to use codeigniter not so long ago and i got small problem.

I try to get comment from db as
            $q = $this->CI->db->query("Select * from comments where item_id = '".$id."' and item='page'");
            if($q->num_rows()>0){
                 return $q->result_array();
            }else{
				return false;
			}  

Open in new window


and then in view file i just put

<? if(is_array($comments)){
		foreach($comments as $comment){	
?>

<div class="testimonials-item">
        			<p class="testimonials-item-text"><? echo $comment[message];?></p>
        			<p class="testimonials-item-author"><? echo $comment[author];?></p>
</div>
                


<?		}	
	}
?>

Open in new window



but i got problem

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant message - assumed 'message'

Filename: views/add_comments.php

Line Number: 8

What can make this error. How i can fix it.
0
Comment
Question by:umaxim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
ID: 37789583
echo $comment[message];

should be

echo $comment['message'];

and 'author' likewise
0
 
LVL 1

Author Comment

by:umaxim
ID: 37789603
is it requirements of php or why it ask for ''
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37789634
it's just php syntax.
You specify an array's index either...

1. Using a literal integer:
        $array[0];

2. Using a literal string:
        $array['zero'];
        $array["zero"];

3. Using another variable which holds either an integer or a string:
        $index = 0;
        $array[$index];  // same as $array[0]
        $index = "zero";
        $array[$index];  // same as $array["zero"]

4. Using a constant which holds either an integer or a string:
        define('zero', 0);
        $array[zero];  // same as $array[0]

In your case, you are trying to specify a string index, so you need to quote it in order for php to understand you are trying to specify a string and not a constant or a variable.
0
 
LVL 1

Author Comment

by:umaxim
ID: 37789659
thanks for explanation.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question