我正在通过字段emp_id
获取雇主记录,如果多个行在First
中共享相同的值,我想打印全名,而不是仅打印他的第一行。
另外,我如何调整条件表达式以使用新查询?
这是我要修复的代码:
<?php
$emp = mysql_query("SELECT * FROM employees
WHERE s_id = '" .$s. "' ORDER BY emp_id ASC");
while($names = mysql_fetch_array($emp)) {
if ($names['Show'] == 'TRUE'){
?>
<table width="100%" class="round1" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="7.5%" class="name_phone"
<div>
<?php
if (($names['First'] == $names['First']) && ($names['u_id'] != $names['u_id']))
{echo $names['First'];}
else
{echo $names['First']. ' ' .$names['Last'];} ?>
</div>
</td>
</tr>
<tr>
<td class="phone">
<div>
<?php if ($names['ShowPhone'] == 'TRUE')
{echo $names['Phone'];}
else
{echo ' ';} ?>
</div>
</td>
</tr>
</table>
<?php }} ?>
答案 0 :(得分:1)
您需要使用双==
进行相等比较。
<?php
if (($names['First'] == $names['First']) && ($names['u_id'] != $names['u_id']))
{echo $names['First'];}
else
{echo $names['First']. ' ' .$names['Last'];}
?>
答案 1 :(得分:0)
对于php中的比较,您使用的是==
或===
(或!=
或!==
),您正在使用赋值运算符。
答案 2 :(得分:0)
修复代码:
<?php
if (($names['First'] == $names['First']) && ($names['u_id'] == $names['u_id']))
{echo $names['First'];}
else
{echo $names['First']. ' ' .$names['Last'];}
?>