php - Simple function in dynamic table -
can tell me i'm doing wrong? learned how create function , display inside dynamic table - think. i've been tweaking it, changing variables, etc., can't work.
i inserted following script before while loop.
function get_stars2($latin) { $stars2 = ''; { switch($latin) { case 'aix sponsa': case 'gavia immer': return '<sup><span style="color: #f00;"><b>+</b></span></sup>'; break; default: return $stars2; break; } } }
$latin defined inside while loop, told doesn't matter; function can take care of outside while loop.
and here's how inserted function inside table:
<td>'.$row['symbol'].'</a>'.get_stars2($latin).$desigast.'</td>
note: commented it's bad form use functions display html, let me explain what's going on here. working on rather complex dynamic reference table - series of tables. 1 of files suffering code bloat, put series of php switches in separate file , included them, using require_once. how learned require_once nixes while loop; in other words, action can occur once. if change require_once require, entire file included once every row in table.
so asked alternatives, , told need use function, have limited experience with. there other alternatives, little on head. think either need learn how work functions or jazz database tables can handle annotation , footnotes in reference tables.
why of convoluted logic?
function get_stars2($latin) { if ($latin) return '<sup><span style="color: #f00;"><b>+</b></span> </sup>'; }
even better, wrap in
if ($latin) { foo(); }
also, it's considered bad form have php functions return html.
also, code works. maybe you're not using echo
command.
Comments
Post a Comment