3

I want to Print some dynamically data from my function to passing string in function like this.

My Function

function mysql_funX_Repeter($query,$itemtemplet)
{
    $this->mysql_funX_connect();

    $result = mysql_query($query) or die("Repeter Query Error.");
    if (!$result) 
    {
        $message = 'ERROR:' . mysql_error();
        return $message;
    }
    else
    {
        $newtempelt = str_replace("Eval", '$row', $itemtemplet);
        while ($row = mysql_fetch_array($result)) 
        {

            echo $newtempelt;
        }
    }
}

Passing Value In Function

<ul>
<?php
$rptvalue="<li><a href=''>Eval['name']</a></li>";
$myFun->mysql_funX_Repeter("Select name from tbldemo",$rptvalue);
?>
</ul>

My Output

  • $row['name']
  • $row['name']
  • $row['name']

I want Output

  • raj

  • ram

  • prince

But it's Show me only variable but not show it's database value. How to solve this...!!!

  • I'm not sure why this is, I suspect it is a safeguard. Here's a simpler usage case. `$row['name'] = 'test'; $rptvalue="
  • Eval['name']
  • "; echo str_replace("Eval", '$row', $rptvalue);` – chris85 Apr 03 '15 at 00:01
  • No, sir It's Can't Work. It's Show like `$row['name']` – Priyank Patel Apr 03 '15 at 00:23
  • I'm unfamiliar with this behavior and haven't been able to find any documentation on it. The code I posted is a simpler form of your code to demonstrate the issue; so others that come here can reproduce the issue quicker and might know the cause. – chris85 Apr 03 '15 at 03:56
  • Really you should try to avoid the mysql_ function as they are depreciated [See here](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1). The answer to this question [http://stackoverflow.com/questions/7574437/php-problem-with-function-and-eval-on-array](http://stackoverflow.com/questions/7574437/php-problem-with-function-and-eval-on-array) Shows a way of doing what you require. – Jonny C Apr 13 '15 at 10:59