Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/107844-str-replace-with-a-function/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.