html - Font Awesome icons not rendering when I use PHP echo? -
i'm trying set menu list pulls array mysql query , uses foreach echo out each list element.
i'm using font awesome, , reason when place <i>
elements inside of echo line, icons not render. other icons on same page rendering fine.
i've verified of css
files being included properly.
here block of code, can see generating icon names using str_replace()
, there other icons in echo static.
i'm pulling hair out here.
$result = mysqli_query($con,"select * outageupdates order timestamp"); while($row = mysqli_fetch_array($result)) { $time = strtotime($row[timestamp]); $time = date("h:i", $time); $icon = str_replace("internal", "fa-user", $row[type]); $icon = str_replace("external", "fa-user-times", $row[type]); echo '<li><a href="outageupdates.php"><i class="fa ' . $icon . '"></i>' . $row[agentname] . ' - ' . $row[type] . '<small class="pull-right"><i class="fa fa-clock"></i>' . $time . '</small></a></li>'; }
what's happening you're re-assigning $icon
invalid icon class string if $row['type']
contains other "external".
say $row['type']
(and don't forget use quotes array keys), contains "internal". after
$icon = str_replace("internal", "fa-user", $row['type']);
$icon
"fa-user". then, after
$icon = str_replace("external", "fa-user-times", $row['type']);
$icon
"internal".
assuming $row['type']
may either "internal" or "external", i'd use instead
$icon = $row['type'] == 'internal' ? 'fa-user' : 'fa-user-times';
alternatively, use switch statement if have other types
switch($row['type']) { case 'internal': $icon = 'fa-user'; break; case 'external': $icon = 'fa-user-times'; break; case 'admin': $icon = 'fa-cogs'; break; default: $icon = 'fa-question-circle'; }
Comments
Post a Comment