?
Solved

Codeigniter

Posted on 2012-03-30
4
Medium Priority
?
348 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 2000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

771 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