0

Sorry for posting like this but I am learning I want all the results to have a hr or any html based line except the last one I put a line break but it won't look good help me

foreach ($newsqry->result() as $n) {
    $nr=$n->numrows();
    $nlink = array_keys($routesAll, "news/index/" . $n->n_id);
    ?>
            <div class="row">
            <div class="col-md-6 imgpost">
                            <a class="post-imgn" href="<?=site_url($nlink)?>">
                                <img  class=""src="<?=base_url("assets/uploads/news/thmb/$n->img")?>"alt="<?=character_limiter($n->title,'50')?>">
                            </a>
                        </div>
                            <div class="col-md-6 descpost">
                                <div class="post-category com" >
             <?php
    $t = $n->tags;
    $s = explode(',', $t);
    foreach ($s as $a) {
        ?>
                            <a class="tags" href="<?=site_url("news/view?tag=".strtolower(str_replace(' ','-',$a)))?>"><?=ucwords($a)?></a>
                        <?php } ?>
            </div>
                                <h3 class="post-title news">
                                    <a href="<?=site_url($nlink)?>"><?=character_limiter($n->title,'100')?>"</a>
                                </h3>
                                <ul class="post-meta">
                                    <li><a href="<?=site_url("news/view?author=".strtolower(str_replace(' ','-',$n->author)))?>"><?=$n->author?></a></li>
                                    <li><i class="fa fa-clock-o" aria-hidden="true"></i> <?=date("h:i A",strtotime($n->time))?> <?=date("F-d-y",strtotime($n->date))?></li>
                                </ul>
                                <p class="descfornews"><?=character_limiter(strip_tags($n->desc),'190')?></p>
                            </div>
                        </div>
                        <?php if($nr<1){echo "<hr>";}else{ echo "<h3>End of Page</h3>";}?>
                <?php
}
?>

  • you can do this with css: `hr:last-of-type{display:none;}` – Vickel Feb 02 '21 at 18:04
  • What layer does this code exist in? If this is a controller or a view then I shouldn't see `$newsqry->result()`. If this is a model script, then I shouldn't see any html markup nor any printing to screen. I smell a complete refactor in your near future. – mickmackusa Feb 05 '21 at 08:00
  • Its in the view – Anurag Thapa Mar 07 '21 at 06:22

1 Answers1

0

I think you can do something like this. it will print


before the data printed, but there is $data variable to prevent it to print before the first data.
 <?php
        $data = 0;
        $t = $n->tags;
        $s = explode(',', $t);
        foreach ($s as $a) {
          if($data!=0){echo "<hr>";}
            ?>
            <a class="tags" href="<?=site_url("news/view?tag=".strtolower(str_replace(' ','-',$a)))?>"><?=ucwords($a)?></a>
        </div>
            <h3 class="post-title news"><a href="<?=site_url($nlink)?>"><?=character_limiter($n->title,'100')?>"</a></h3>
                  <ul class="post-meta">
                        <li>
                            <a
                                href="<?=site_url("news/view?author=".strtolower(str_replace(' ','-',$n->author)))?>"><?=$n->author?></a>
                        </li>
                        <li>
                      <i class="fa fa-clock-o" aria-hidden="true"></i>
                      <?=date("h:i A",strtotime($n->time))?>
                      <?=date("F-d-y",strtotime($n->date))?></li>
                  </ul>
            <p class="descfornews"><?=character_limiter(strip_tags($n->desc),'190')?></p>
        </div>
        </div>
        
    <?php
    }
        echo("<h3>End of Page</h3>");
    ?>
Daffa Akbari
  • 135
  • 7