shan Posted October 30, 2015 Share Posted October 30, 2015 hi guys im actually perplexed with this problem where im not able to read anything from DB, when i var dump the object it just outputs bool(false). dont know where im going wrong, Pl help me here is the code logic for status_list page where status_reply resides which i want to read from DB and display it:- $status2view=$project->statusView($f_uname); foreach($status2view as $row){ //print_r($row); $updateid=$row['update_id']; //gives output on var_dump // print_r($updateid); (gives output) $status_reply_=$project->reply2StatusView($updateid); print_r($status_reply_); foreach ($status_reply_ as $row) { $status_reply_id=$row['update_id']; $reply_author=$row['author']; $reply_d=htmlentities($row['update_body']); $reply_data= stripslashes($reply_d); $reply_t= htmlentities($row['title']); $reply_title= stripslashes($reply_t); $account_name=$row['account_name']; $reply_date=$row['time']; $reply_delete_button=""; if ($reply_author==$session_uname || $account_name==$session_uname) { $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>"; } $status_replies="<div class='replyboxes pull-left reply".$status_reply_id."'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a><span class='pull-right'>".$reply_date ."</pan><legend>" . "<b class='caret'> <button type='button' class='btn btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span> <ul class='dropdown-menu'>".$reply_delete_button . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil reply".$status_reply_id."' title='Edit this comment' >Edit</a></li>" . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>" . "</button></b></legend><br>". html_entity_decode($reply_data).""; } } foreach ($status2view as $row1) { //got values here. $updateid=$row1['update_id']; $account_name=$row1['account_name']; $os_id=$row1['os_id']; $author=$row1['author']; $post_date=$row1['time']; $title= stripslashes($row1['title']); $data= stripslashes($row1['update_body']); $statusdeletebutton=''; //insert_status_ui script to get message. if($isowner=="yes"){ $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_session session_editor".$updateid." jumbotron'>" . "<a href='#' type='".$updateid."' class='pull-right close_edit' title='Close without editing'>Close X</a>" . "<input type='text' class='form-control title_s_edit title_s_".$updateid."' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >" . "<span> </span>" . "<textarea id='wall_edit_1' type='".$updateid."' rows='5' cols='50' class='session_edit text_value_".$updateid."' wrap='hard' placeholder='whats up ".$session_uname."'> ".html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' value='".$updateid."' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div>" ; } elseif ($is_friend==TRUE&&$session_uname!=$f_uname) { $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_friend friend_editor".$updateid." jumbotron'>" . "<a title='Close without editing' type='".$updateid."' href='#' class='pull-right close_edit_f'>Close X</a>" . "<input type='text' class='form-control title_f_edit title_f_".$updateid."'' name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>" . "<div> </div>" . "<textarea id='wall_edit_2' value='' type='".$updateid."' rows='5' cols='50' class='friend_edit update_friend_".$updateid."' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>" .html_entity_decode($data)."</textarea><br>" . "<button style='float:right;' value='".$updateid."' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button></form></div>"; } if ($author==$session_uname || $account_name==$session_uname) { $statusdeletebutton='<li>' . '<a href="#" type="'.$updateid.'" class="delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li>'; } if($isowner=="yes"){ $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.' jumbotron">' . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">' . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>' . '<span class="pull-right">' . '<div class="dropdown">' . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" >' . '<span class="glyphicon glyphicon-edit"></span></button>' . '<ul class="dropdown-menu">' . '<li><a href="#" attr="'.$updateid.'" type="'.$updateid.'" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'.$statusdeletebutton.'</ul></div></span><br><hr>' . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">' . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:- <a href="search_results.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br><p>'.$status_replies.'</p><br>'; if ($is_friend==TRUE||$session_uname==$f_uname) { $status_list.= '<textarea id="'.$updateid.'" class="status_reply_'.$updateid.' input-custom2" placeholder="comment\'s"></textarea>' . '<button id="reply_btn_'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>'; } }elseif ($is_friend==TRUE&&$session_uname!=$f_uname) { $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.' jumbotron">' . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">' . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3><br><hr>' . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">' . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:- <a href="search_results.php?u='.$author.'">'.$author. '</a> '.$post_date.'</small></b>' . '<br><p>'.$status_replies.'</p><br>'; $status_list.= '<textarea id="'.$updateid.'" class="status_update input-custom2" placeholder="comment\'s"></textarea>' . '<button id="reply_btn'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>'; } echo $status_list; } the above code is called in home and search results page through include_once function. if you need any details please do ask me for it Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 30, 2015 Share Posted October 30, 2015 When you throw a bunch of class-related code at us and give us way too much to look at without fully understanding the goal, it makes us not want to help you. Try debugging each of your methods to be sure that they are doing EXACTLY what you expect. Once you are happy with them, do the same debugging with your surrounding logic to be sure that you are giving those methods what they expect and that the returns are what you expect still. When you get down to one single point of contention - show us that roadblock and tell us what is not working. Quote Link to comment Share on other sites More sharing options...
shan Posted October 30, 2015 Author Share Posted October 30, 2015 (edited) @ginerjm sorry about the mess. it is not working in the instantiated object. $status_reply_=$project->reply2StatusView($updateid); its outputting bool(false) when var_dumped. (edited) here is the method: public function reply2StatusView($updateid){ $stmth= $this->_db->prepare("select * from updates where update_id=:statusid and type='b' order by time asc"); $stmth->bindparam(":statusid", $updateid); $stmth->execute(); return $stmth->fetchAll(PDO::FETCH_ASSOC); Edited October 30, 2015 by shan Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 30, 2015 Share Posted October 30, 2015 So your returned value is False. That implies that the execute failed. Never write code that "does" something that could fail without checking the result. Especially a class where you plan on using it a lot. So - test the execute and display the error (on screen during development or in your error_log once in production). Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted October 30, 2015 Share Posted October 30, 2015 it would seem that you have removed the code you previously had that was setting the PDO error mode to exceptions. the false value being returned means that the execute statement failed and an exception wasn't thrown for the error. so, why did you remove (or not copy) the error setting you did have in your code? 1 Quote Link to comment Share on other sites More sharing options...
shan Posted November 2, 2015 Author Share Posted November 2, 2015 it would seem that you have removed the code you previously had that was setting the PDO error mode to exceptions. the false value being returned means that the execute statement failed and an exception wasn't thrown for the error. so, why did you remove (or not copy) the error setting you did have in your code? actually i changed it because of an advice given to me by a friend. And even after changing the code im not getting output. any help would be appreciated: here is the updated code: include '../includes/dbconfig.inc.php'; $status2view=$project->statusView($_SESSION['uname']); foreach($status2view as $row){ //print_r($row); $updateid=$row['update_id']; //gives output on var_dump // print_r($updateid); (gives output) $stmth= $conn->prepare("select * from updates where update_id=:statusid and type='b' order by time asc"); $stmth->bindparam(":statusid", $updateid); $stmth->execute(); $status_reply_=$stmth->fetchAll(PDO::FETCH_ASSOC); print_r($status_reply_);//no output foreach ($status_reply_ as $row) { $status_reply_id=$row['update_id']; $reply_author=$row['author']; $reply_d=htmlentities($row['update_body']); $reply_data= stripslashes($reply_d); $reply_t= htmlentities($row['title']); $reply_title= stripslashes($reply_t); $account_name=$row['account_name']; $reply_date=$row['time']; $reply_delete_button=""; if ($reply_author==$session_uname || $account_name==$session_uname) { $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>"; } $status_replies="<div class='replyboxes pull-left reply".$status_reply_id."'><b>Reply by<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a><span class='pull-right'>".$reply_date ."</pan><legend>" . "<b class='caret'> <button type='button' class='btn btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span> <ul class='dropdown-menu'>".$reply_delete_button . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil reply".$status_reply_id."' title='Edit this comment' >Edit</a></li>" . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>" . "</button></b></legend><br>". html_entity_decode($reply_data).""; } } Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 2, 2015 Share Posted November 2, 2015 So did you activate PDO exceptions again? Is your PHP error reporting on? What do you mean by “no output”? An empty array? The boolean false? We cannot magically fix your code just by looking at it. Since only you can run it, you must provide us with the relevant info. 1 Quote Link to comment Share on other sites More sharing options...
shan Posted November 2, 2015 Author Share Posted November 2, 2015 So did you activate PDO exceptions again? Is your PHP error reporting on? What do you mean by “no output”? An empty array? The boolean false? We cannot magically fix your code just by looking at it. Since only you can run it, you must provide us with the relevant info. i'm sorry for being hasty bro, it doesnt throw any errors, except the empty array. and btw i changed the code as above still no luck with it. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 2, 2015 Share Posted November 2, 2015 An empty array is not an error. Are you absolutely sure that the query should return rows? Have you checked it by running the underlying query in phpmyadmin? Quote Link to comment Share on other sites More sharing options...
shan Posted November 2, 2015 Author Share Posted November 2, 2015 well it is returning rows in phpmyadmin bro! but not in my example project Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted November 2, 2015 Solution Share Posted November 2, 2015 So you're saying that when you var_dump() your $updateid variable, literally copy it into the query string and run the query, you do get results? Are you sure you're accessing the right database? What happens when you hard-code the ID into the PDO query? 1 Quote Link to comment Share on other sites More sharing options...
shan Posted November 2, 2015 Author Share Posted November 2, 2015 thanks actually i was feeding the wrong id in to the database bro thanks for pointing it out. Quote Link to comment 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.