eval attend du php derrière donc faut mettre le ; a la fin, eval tout seul dans ton cas fera pas grand chose, donc faut mettre un echo dans le coin
si l’équation est toujours la même seul les valeur change, tu pourrai même mettre direct le résultat en mysql
Ok, ça marche mieux, j'ai bien le résultat qui s'affiche, mais pas où il devrait.
J'ai le tableau suivant :
echo "<table border=\"1\" cellpadding=\"5\">" . "\n";
echo "<thead>" . "\n";
echo "<tr>" . "\n";
echo "<th>#</th>" . "\n";
echo "<th>Prénom</th>" . "\n";
echo "<th>Salaire</th>" . "\n";
echo "<th>Résultats</th>" . "\n";
echo "<th>Objectifs</th>" . "\n";
echo "<th>Part variable</th>" . "\n";
echo "<th>Actions</th>" . "\n";
echo "</tr>" . "\n";
echo "</thead>" . "\n";
echo "<tbody>" . "\n";
foreach($employes as $employe) {
echo "<tr>" . "\n";
echo "<td>".$employe->get_id()."</td>" . "\n";
echo "<td>".$employe->get_prenom()."</td>" . "\n";
echo "<td>".$employe->get_salaire()."</td>" . "\n";
echo "<td>".$employe->get_resultats()."</td>" . "\n";
echo "<td>".$employe->get_objectifs()."</td>" . "\n";
echo "<td>".$employe->get_part_variable($config)."</td>" . "\n";
echo "<td><a href=\"edit.php?user_id=".$employe->get_id()."\">modifier</a> - <a href=\"index.php?action=delete_user&user_id=".$employe->get_id()."\">supprimer</a></td>" . "\n";
echo "</tr>" . "\n";
}
echo "</tbody>" . "\n";
echo "</table>" . "\n";
et ma fonction get_part_variable() : (6e td du tableau)
function get_part_variable($config) {
$equation = $config->get_equation();
$equation = str_replace("%RESULTATS%", $this->user_resultats, $equation);
$equation = str_replace("%OBJECTIFS%", $this->user_objectifs, $equation);
eval("echo ".$equation.";");
}
et voilà le code source généré :
<table border="1" cellpadding="5">
<thead>
<tr>
<th>#</th>
<th>Prénom</th>
<th>Salaire</th>
<th>Résultats</th>
<th>Objectifs</th>
<th>Part variable</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>David</td>
<td>45000</td>
<td>55000</td>
<td>50000</td>
500<td></td>
<td><a href="edit.php?user_id=2">modifier</a> - <a href="index.php?action=delete_user&user_id=2">supprimer</a></td>
</tr>
</tbody>
</table>
Etrangement, le 6e <td> se place après la valeur, ce qui fait que ma valeur s'affiche en dehors du tableau. A quoi est-ce du ?
Et pour répondre à ta question, hélas non, l'équation peut être amené à changer, c'est pour cela que je la stocke en base de données.
[quote="stealth35"]eval attend du php derrière donc faut mettre le ; a la fin, eval tout seul dans ton cas fera pas grand chose, donc faut mettre un echo dans le coin
si l’équation est toujours la même seul les valeur change, tu pourrai même mettre direct le résultat en mysql[/quote]
Ok, ça marche mieux, j'ai bien le résultat qui s'affiche, mais pas où il devrait.
J'ai le tableau suivant :
[php]echo "<table border=\"1\" cellpadding=\"5\">" . "\n";
echo "<thead>" . "\n";
echo "<tr>" . "\n";
echo "<th>#</th>" . "\n";
echo "<th>Prénom</th>" . "\n";
echo "<th>Salaire</th>" . "\n";
echo "<th>Résultats</th>" . "\n";
echo "<th>Objectifs</th>" . "\n";
echo "<th>Part variable</th>" . "\n";
echo "<th>Actions</th>" . "\n";
echo "</tr>" . "\n";
echo "</thead>" . "\n";
echo "<tbody>" . "\n";
foreach($employes as $employe) {
echo "<tr>" . "\n";
echo "<td>".$employe->get_id()."</td>" . "\n";
echo "<td>".$employe->get_prenom()."</td>" . "\n";
echo "<td>".$employe->get_salaire()."</td>" . "\n";
echo "<td>".$employe->get_resultats()."</td>" . "\n";
echo "<td>".$employe->get_objectifs()."</td>" . "\n";
echo "<td>".$employe->get_part_variable($config)."</td>" . "\n";
echo "<td><a href=\"edit.php?user_id=".$employe->get_id()."\">modifier</a> - <a href=\"index.php?action=delete_user&user_id=".$employe->get_id()."\">supprimer</a></td>" . "\n";
echo "</tr>" . "\n";
}
echo "</tbody>" . "\n";
echo "</table>" . "\n";[/php]
et ma fonction get_part_variable() : (6e td du tableau)
[php]function get_part_variable($config) {
$equation = $config->get_equation();
$equation = str_replace("%RESULTATS%", $this->user_resultats, $equation);
$equation = str_replace("%OBJECTIFS%", $this->user_objectifs, $equation);
eval("echo ".$equation.";");
}[/php]
et voilà le code source généré :
[html]<table border="1" cellpadding="5">
<thead>
<tr>
<th>#</th>
<th>Prénom</th>
<th>Salaire</th>
<th>Résultats</th>
<th>Objectifs</th>
<th>Part variable</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>David</td>
<td>45000</td>
<td>55000</td>
<td>50000</td>
500<td></td>
<td><a href="edit.php?user_id=2">modifier</a> - <a href="index.php?action=delete_user&user_id=2">supprimer</a></td>
</tr>
</tbody>
</table>
[/html]
Etrangement, le 6e <td> se place après la valeur, ce qui fait que ma valeur s'affiche en dehors du tableau. A quoi est-ce du ?
Et pour répondre à ta question, hélas non, l'équation peut être amené à changer, c'est pour cela que je la stocke en base de données.