我在html中有一个可排序的表格,并希望在每个表格标题中放置一个add.png,以便如果用户想要添加另一个add.png -他们只需单击该url并将其重定向到addurl.php (如果他们单击外部,它仍然会像正常一样对表格进行排序)。现在,当我单击.png和/或在它外部时,它正在排序。如果这件事做不到,我也想过试着用add another site添加最后一行,但不知道如何将它添加到$j++中,这样它就会出现在最后一行。
what it looks like
PHP代码段
<table class="datatable sortable selectable full">
<thead>
<tr class="theader">
<th width="100%">
<b><li><img src="images/logos/googlebuzz-2-icon.png" height="18" border="0" />Google <a href="addurl.php"><img src="img/icons/add.png" height="18" border="0" align="right"/></a></li></b>
</th>
<th>
<b>Coins</b>
</th>
<th>
<b>CPC</b>
</th>
</tr>
</thead>
<tbody>
<?
$site2 = mysql_query("SELECT * FROM `sites` WHERE `user`='{$data->login}' ORDER BY `cpc` DESC");
for($j=1; $site = mysql_fetch_object($site2); $j++)
{
?>
<tr>
<td>
<? if($site->banned == 1){ ?><font color="red"><? }else{ ?><font color="green"><? } echo($site->title); ?></font><a href="editurl.php?id=<? echo $site->id;?>" class="action-button-small" title="Edit URL"><span class="edit"></span></a>
</td>
<td align="right">
<? if($site->points <= 10){ ?><font color="red"><? }else{ ?><font color="green"><? } echo($site->points); ?></font><a href="addcoins.php?id=<? echo $site->id;?>" class="action-button-small" title="Add Coins"><span class="add"></span></a>
</td>
<td>
<? echo $site->cpc;?>
</td>
</tr>
<?}?>
</tbody>
</table>发布于 2012-02-10 23:30:44
首先,您应该使用while而不是for循环
while($site = mysql_fetch_object($site2))如果要添加最后一行,只需将其添加到迭代之外,在</tbody>之前
<tbody>
<? while($site = mysql_fetch_object($site2)): ?>
<tr>
<td>
<? if($site->banned == 1){ ?><font color="red"><? }else{ ?><font color="green"><? } echo($site->title); ?></font><a href="editurl.php?id=<? echo $site->id;?>" class="action-button-small" title="Edit URL"><span class="edit"></span></a>
</td>
<td align="right">
<? if($site->points <= 10){ ?><font color="red"><? }else{ ?><font color="green"><? } echo($site->points); ?></font><a href="addcoins.php?id=<? echo $site->id;?>" class="action-button-small" title="Add Coins"><span class="add"></span></a>
</td>
<td>
<? echo $site->cpc;?>
</td>
</tr>
<? endwhile; ?>
<tr>
<td colspan="3">
<a href="addurl.php">[add another site]</a>
</td>
</tr>
</tbody>您似乎正在使用javascript进行排序。我不知道是否可以更改它,以便标题中的add按钮有效。
发布于 2012-02-10 23:24:35
您可以通过检查所有行的实际行来检查它是否是最后一行:
$site2 = mysql_query("SELECT * FROM `sites` WHERE `user`='{$data->login}' ORDER BY `cpc` DESC");
$rows = mysql_num_rows($site2);
$i = 0;并将此代码添加到for循环中:
$i++;
if($rows == $i) {
// do something only at the final row
}https://stackoverflow.com/questions/9229854
复制相似问题