Handige Harrie
Handige Harrie

Reputation: 149

my <ul> dissapears when generating <li> in PHP?

I'm having a weird error where my UL tag dissapears when I generate LI tags in it, I have no idea what it could be so if anyone here could help me that would be great.

The HTML it gets generated in:

<div class="col-md-12 col-xs-12">
    <div id="tickets">
        <ul>'.$Ticket->generateTickets().'</ul>
    </div>
</div>

My PHP function

public function generateTickets(){
    $cols = Array ('ID','description','ticket_id');
    $items = $this->db->orderBy('ID')->get("tickets", null, $cols);
    if ($this->db->count > 0){
        foreach ($items as $item) { 
            echo '<li><a href="?p=support&action=readticket&tid='.$item['ID'].'">Ticket #'.$item['ticket_id'].'<br/></a>
            <p>'.substr($item['description'],0,20).'..</p>
            </li>';
        }
    }
}

console showing that the ul just dissapeared: http://piclair.com/r45q7

Upvotes: 0

Views: 64

Answers (1)

MSTannu
MSTannu

Reputation: 1033

In your generateTickets function, you're echoing immediately. Since the concatenation in your html file is done after the function is done, they get output first. You should either return the values ( replace echo with return and move it out of the loop ) or in html, dont concatenate strings.

$result = '';
foreach ( $items as $item ) {
    $result .= '<li ...';
}
return $result;

Upvotes: 4

Related Questions