My PHP function for sidebar element generation looks like that
开发者_开发技巧function makeSidebarEl ($side, $name, $lang, $db)
{
$title='title_'.$lang;
$txt='txt_'.$lang;
$query=$db->query("SELECT $title, $txt FROM sidebar WHERE side='$side' AND name='$name'");
$result=$query->fetch_array(MYSQLI_BOTH);
$title=makeTitle($result[$title], $lang, $db);
$txt=makeTxt($result[$txt], $lang, $db);
echo '<div class="nav">'.$title.$txt.'</div>'."\n";
}
But i'm getting result something like this
<div class="nav"></div>
<div class="nav_1"><img border="0" src=core/design/img/left_nav.png alt="" height="25px"/></div>
...
I mean it opens and closes <div class="nav"></div>
at the begining of the every element but in fact function must echo result within this div:
echo '<div class="nav">'.$title.$text.'</div>'."\n";
How to fix that problem?
UPDATE
function makeTitle($title) {
echo '<div class="nav_1"><img border="0" src=core/design/img/left_nav.png alt="" height="25px"/></div>
<div class="nav_2">'.$title.'</div>
<div class="nav_3"><img border="0" src=core/design/img/left_nav.png alt="" height="25px"/></div>
<div style="clear:both;"></div>';
}
function makeTxt($txt) {
echo '<div id="parts" class="parts_txt">'.$txt.'</div>';
}
makeTitle()
and makeText()
should return
strings rather than echo
them.
As it is now, they echo
text when they are called and return NULL
, which is then concatenated into string when you call echo '<div class="nav">'.$title.$txt.'</div>'."\n";
, i.e., that line evaluates to echo '<div class="nav">'.NULL.NULL.'</div>'."\n";
You need to replace echo
to return
at functions makeTitle
and makeTxt
精彩评论