Solved

Codeigniter

Posted on 2012-03-30
4
340 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now