unemployment Posted March 30, 2011 Share Posted March 30, 2011 I am trying to echo the count for blog posts that have not been review yet, but I get this error. Notice: Undefined index: status but I feel like I have defined my status in my query. Plus my query is working as I have checked it in phpmyadmin Here is my function: function unapproved_post_counter() { $sql = "SELECT COUNT(`approved`) AS `status` FROM `blog_posts` WHERE `approved` = 0 "; $result = mysql_query($sql); $data = array(); while (($row = mysql_fetch_assoc($result)) !== false) { $data[] = $row; } return $data; } Here is how I am echoing it. $count = unapproved_post_counter(); <h1>Blog<span class="blogadds f_right"><?php echo $count['status']; ?> New Articles</span> print_r($count) tells me this... Array ( [0] => Array ( [status] => 2 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/232172-cant-echo-the-count/ Share on other sites More sharing options...
KevinM1 Posted March 30, 2011 Share Posted March 30, 2011 You have a two dimensional array. You need to echo $count[i]['status'], where i is the index of the inner array you want. Quote Link to comment https://forums.phpfreaks.com/topic/232172-cant-echo-the-count/#findComment-1194331 Share on other sites More sharing options...
unemployment Posted March 30, 2011 Author Share Posted March 30, 2011 Ahh thanks.... Big oversight. I just decided to make it one dimensional to simplify things. Not sure what I was thinking. Quote Link to comment https://forums.phpfreaks.com/topic/232172-cant-echo-the-count/#findComment-1194336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.