Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Codeigniter

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 …
Suggested Courses

604 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