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
Solved

Codeigniter

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

860 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