PHP就在这里:
<?php
$sth = $conn->prepare('SELECT employee.name, employee.type, employee.rate, work.overtime, work.leaves, work.ticket FROM employee, work');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row ){
if($row['name']!=""){
?>
HTML:
<tr>
<td>
<input type="text" placeholder="Name" value="<?php echo $row['name']?>"/>
</td>
<td>
<input type="text" placeholder="Type" value="<?php echo $row['type']?>"/>
</td>
<td>
<input type="text" placeholder="Rate" value="<?php echo $row['rate']?>"/>
</td>
<td>
<input type="text" placeholder="OT" value="<?php echo $row['overtime']?>"/>
</td>
<td>
<input type="text" placeholder="Leaves" value="<?php echo $row['leaves']?>"/>
</td>
<td>
<input type="text" placeholder="Total" value="<?php echo $row['ticket']?>"/>
</td>
</tr>
名称在两者之间很常见。
如何显示数据?
答案 0 :(得分:3)
您正在寻找的术语是JOIN
。阅读MySQL Official Doc
答案 1 :(得分:0)
a => (a < 10) ? 'valid' : 'invalid'
然后您的HTML代码将如下所示(确保您在<?php
$sth = $conn->prepare('SELECT employee.name, employee.type, employee.rate, work.overtime, work.leaves, work.ticket FROM employee left join work on employee.name=work.name');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row ){
if($row['name']!=""){
?>
代码下使用<tr>
。)
<table>
我在这里使用左连接,因为您可能需要所有员工姓名。如果你只想要这两个表之间的公共记录,那么只需使用内连接而不是左连接。