This error is blowing my mind. I am querying an SQL database and placing the result in an array. When I do a print_r of the array ($contest) I get this:
stdClass Object ( [id] => 1 [title] => title [description] => description [start_date] => 2009-08-30 [end_date] => 2009-08-31 )
yet when I do echo $contest['title'] (or any of the array key's) the script stops executing, no error message, no nothing.
I can provide more code if it is necessary. I am at my wits end. Thanks!
Can print_r($array) but not echo $array['value']
Moderator: General Moderators
-
davidcroda
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 08, 2006 10:36 am
Re: Can print_r($array) but not echo $array['value']
$contest isn't an array.
stdClass Object
Re: Can print_r($array) but not echo $array['value']
You are returning it as an object as opposed to an array.
Try:
Try:
Code: Select all
<?php
echo $contest->title; // As opposed to $contest['title'];
?>Code: Select all
<?php
$query = "SELECT * FROM mytable WHERE id='1'";
$result = $mysqli->query($query); // $result now contains an object
$contest = $result->fetch_assoc(); // $contest now contains an associative array of all the fields in the selected row
?>-
davidcroda
- Forum Newbie
- Posts: 9
- Joined: Wed Nov 08, 2006 10:36 am
Re: Can print_r($array) but not echo $array['value']
You guys are amazing. I just looked in the error log and found
PHP Catchable fatal error: Object of class stdClass could not be converted to string
I wish I could have the past 2 hours back.
Feel free to delete or close this post. Thanks again!
PHP Catchable fatal error: Object of class stdClass could not be converted to string
I wish I could have the past 2 hours back.
Feel free to delete or close this post. Thanks again!