FlightDeckES Posted June 1, 2019 Report Share Posted June 1, 2019 Hello I need your help please I am trying to make the comments visible in the pirep_viewreport I am using this code <?php foreach($comments as $comment) { ?> <p id="row "> <strong><?php echo $comment->firstname. ' '. $comment->lastname ?>: </strong><?php echo $comment->comment; ?> <hr /> </p> <?php } ?> http://i65.tinypic.com/2zibvut.png but I have this error thanks for the help thanks Quote Link to comment Share on other sites More sharing options...
Moderators Parkho Posted June 2, 2019 Moderators Report Share Posted June 2, 2019 6 hours ago, sotofigueroa26 said: foreach($comments as $comment) { The error refers to the loop of your code. in fact you haven't set $comments variable to get the required data. You need to first get the data from your DB field and then use the loop to show every records. In order to do so, you need a function that reads records from your table in your DB. Quote Link to comment Share on other sites More sharing options...
FlightDeckES Posted June 2, 2019 Author Report Share Posted June 2, 2019 (edited) Hi, thanks for the help with this code I solved the error but now it gives me another. Here it works right with comments. http://i68.tinypic.com/6z95wm.png here it does not work without comments http://i68.tinypic.com/zl7l0i.png code: <!-- Comentarios --> <div class="card"> <div class="card-title"> <i class="fa fa-commenting-o"></i> <span class="caption-subject bold uppercase"> Comentarios </span> </div> <div class="card-body"> <?php if(!$comments) { echo '<p align="center"><strong>There are no comments for this PIREP</strong></p>'; return; } ?> <div id="dialogresult"></div> <?php foreach($comments as $comment) { ?> <p id="row<?php echo $comment->id;?>"> <strong><?php echo $comment->firstname. ' '. $comment->lastname ?>: </strong><?php echo $comment->comment; ?> <hr /> </p> <?php } ?> <form action="<?php echo url('/pireps/viewpireps');?>" method="post"> <textarea name="comment" style="width:100%; height: 100px"></textarea> <input type="hidden" name="action" value="addcomment" /> <input type="hidden" name="pirepid" value="<?php echo $pirep->pirepid?>" /> <input type="submit" name="submit"class="btn btn-primary btn-block" value="Añadir" /> </div> </div> <!-- Comentarios --> Edited June 2, 2019 by sotofigueroa26 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.