作者tkdmaf (皮皮快跑)
看板PHP
标题Re: [请益] 如何在$row上加超连结?
时间Wed Dec 15 07:37:03 2010
※ 引述《LAOS (LAOS)》之铭言:
: echo "<tr align='center' bgcolor='#EDEAB1'>";
: echo "<td>" . $row["hello"] . "</td>";
: echo "</tr>";
: echo "</form>";
: 如上,从资料库提出hello栏位的值,然後列出,我要在值加上超连结
: 用<a href=""></a>怎麽摆都没办法,有其他解?
<tr align="center" bgcolor = "#EDEAB1">
<td><a href="xxxx.xxx"><?=$row['hello']?></a></td>
</tr>
如果你把echo拿掉,会不会做起来就比你想像的轻松的多?
切记一件事:php的echo输出就是html,既然如此就不需要把html「又」echo一次。
另外如果伺服器预设不支援short tag的话。
就要改成<?php echo $row['hello']?>
如果遇到重复的区段html:
foreach(xxxxx as $row){
echo "<tr align='center' bgcolor = '#EDEAB1'>";
echo "<td><a href='xxxx.xxx'>{$row['hello']}</a></td>";
echo "</tr>";
}
改成这样会显得比较不会杂乱:
<?php foreach(xxxx as $row):?>
<tr align="center" bgcolor = "#EDEAB1">
<td><a href="xxxx.xxx"><?=$row['hello']?></a></td>
</tr>
<?php endforeach;?>
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.104.131.10