2011-02-01 83 views
0

我的eval代碼中的問題在哪裏? 因爲Apache說:在eval()中解析錯誤 - eval()'d代碼

Parse error: syntax error, unexpected T_STRING in E:\xampp\htdocs\1php\mas_res\inc\mysql_class.php(120) : eval()'d code on line 1

我的代碼:

  $type1 = "row"; 
      $query1 = mysql_query("SELECT * FROM table"); 
      $textToEval = "mysql_fetch_{$type1}($query1);"; 
      $query = eval($textToEval); 

什麼是正確的模式?

謝謝..

+0

回顯出你的`$ textToEval`,並將它添加到你的問題中。 – jondavidjohn 2011-02-01 19:09:03

回答

5

不要使用eval!使用PHP的variable functions

$function = 'mysql_fetch_' . $type1; 
$query = $function($query1); 

哦,如果你想知道,什麼是錯:你忘了逃避$query1$。它應該是\$query1

+0

eval()是邪惡的(),請記住! :) – Trufa 2011-02-01 19:39:16