a1amattyj Posted May 29, 2008 Share Posted May 29, 2008 Hello, Im trying to replace a random statement in my html file with a function. HTML: <tr> <td align="right">Category: </td> <td>%{cat}%</td> </tr> PHP: function Category() { echo '<select name="category">'; $query = "SELECT * FROM {$db_prfix}multi_cat"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { if ($row['status'] == '1') { echo ' <option value=' . $row['id'] . '>' . $row['name'] . '</option> '; } } echo '</select>'; } $content_get = file_get_contents("multi_templates/signup.html"); $content_get1 = str_replace('%{cat}%',Category(),$content); echo $content; It's getting the drop down box... just randomly dumping it above everything else in the html... any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/107844-str-replace-with-a-function/ Share on other sites More sharing options...
wildteen88 Posted May 29, 2008 Share Posted May 29, 2008 remove the echo statemtns in your function. Use return instead maybe: function Category() { $html = '<select name="category">'; $query = "SELECT * FROM {$db_prfix}multi_cat"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { if ($row['status'] == '1') { $html .= ' <option value=' . $row['id'] . '>' . $row['name'] . '</option> '; } } $html .= '</select>'; return $html; } $content = file_get_contents("multi_templates/signup.html"); $content = str_replace('%{cat}%', Category(), $content); echo $content; If the menu is still going above your table then there must be a bug in the generated HTML. Quote Link to comment https://forums.phpfreaks.com/topic/107844-str-replace-with-a-function/#findComment-552818 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.