PHP ver gevorderde |
|
He,
Ik probeer wat waardes toe te kennen aan variabelen, maar het wil niet erg hard lukken.. Ik heb me er blind op gestaard, het zal iets doms zijn, maar ik zie het écht niet.
Stukje tpl:
<!-- START BLOCK : view_employees -->
<strong>Name | Level | Sale/hour | Cost/hour | Hired on | Fire</strong><br />
<form method="post" action="employ.php?action=fire">
<!-- START BLOCK : employee -->
{name} | {employee_level} | {sale} | {cost} | {hired} | <input type="text" name="fire[{id}]" style="width:40px;" /><br />
<!-- END BLOCK : employee -->
<a href="#" onclick="javascript: document.forms[0].submit();" />Fire employees</a>
</form>
<!-- END BLOCK : view_employees -->
<!-- START BLOCK : view_employees --> <strong>Name | Level | Sale/hour | Cost/hour | Hired on | Fire</strong><br /> <form method="post" action="employ.php?action=fire"> <!-- START BLOCK : employee --> {name} | {employee_level} | {sale} | {cost} | {hired} | <input type="text" name="fire[{id}]" style="width:40px;" /><br /> <!-- END BLOCK : employee --> <a href="#" onclick="javascript: document.forms[0].submit();" />Fire employees</a> </form> <!-- END BLOCK : view_employees -->
En de bijbehorende PHP:
<?php
$qry = mysql_query("SELECT employees.id, employees.name, employees.employee_level, employees.cost, employees.sale,
employees_hired.employee_level, employees_hired.hired
FROM employees INNER JOIN employees_hired ON (employees.employee_level = employees_hired.employee_level)
WHERE memid = ".$_SESSION['id']." ORDER BY employees.employee_level");
if ($emps > 0) {
$tpl -> NewBlock('view_employees');
while ($res = mysql_fetch_assoc($qry)) {
print_r($res);
$tpl -> NewBlock('employee');
foreach ($res as $key => $value) {
$tpl -> Assign($key, $value);
}
}
}
else {
$tpl -> NewBlock('error');
$tpl -> Assign('error', 'No employees hired yet!');
}
?>
<?php $qry = mysql_query("SELECT employees.id, employees.name, employees.employee_level, employees.cost, employees.sale, employees_hired.employee_level, employees_hired.hired FROM employees INNER JOIN employees_hired ON (employees.employee_level = employees_hired.employee_level) WHERE memid = ".$_SESSION['id']." ORDER BY employees.employee_level"); if ($emps > 0) { $tpl -> NewBlock('view_employees'); $tpl -> NewBlock('employee'); foreach ($res as $key => $value) { $tpl -> Assign($key, $value); } } } else { $tpl -> NewBlock('error'); $tpl -> Assign('error', 'No employees hired yet!'); } ?>
Ik krijg de print_r wel te zien, daar staat ook alles in, maar er wordt niets toegekend.
Ik weet dat er geen Prepare() en PrintToScreen() bij staat, want dit PHP-bestand wordt geïnclude, de Prepare() en Printtoscreen() staan op de index.
Dit geeft print_r($res); terug:
Array ( [id] => 15 [name] => Level 15 [employee_level] => 15 [cost] => 400 [sale] => 200 [hired] => 10 )
Array ( [id ] => 15 [name ] => Level 15 [employee_level ] => 15 [cost ] => 400 [sale ] => 200 [hired ] => 10 )
|