标题内带有 url 图像的表格

发布于 2025-01-04 04:51:29 字数 2470 浏览 1 评论 0原文

我有一个 html 中的可排序表,并希望在每个表头中放置一个 add.png ,因此如果用户想要添加另一个 url - 他们只需单击 add.png 并将它们重定向到 addurl.php (如果他们单击外部)仍然会像平常一样对表进行排序)。现在,当我单击 .png 和/或其外部时,它会进行排序。如果这是无法完成的事情,我还考虑过尝试使用 [添加另一个站点] 添加最后一行,但不知道如何将其添加到 $j++ 中,以便它出现在最后一行。

它是什么样的

[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>

I have a sortable table in html and looking to put an add.png inside each table header so if a user wants to add another url - they just click the add.png and redirects them to the addurl.php (if they click outside it will still sort the table just like normal). Right now it sorting when I click on the .png and/or outside it. If this something that can't be done, I've also thought about trying to add a final row with [add another site] but have no idea how to work it into the $j++ so it appears at the final row.

what it looks like

[PHP snippet]

        <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚气少女 2025-01-11 04:51:29

首先,您应该使用 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 进行排序。我不知道是否可以更改,以便标题中的添加按钮起作用。

First of all, instead of a for loop, you should use while:

while($site = mysql_fetch_object($site2))

If you want to add a final row, just add it outside the iteration, before </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>

It seems you are using a javascript to do the sorting. I don't know if that can be changed so your add button in the header works.

青朷 2025-01-11 04:51:29

您可以通过检查所有行的实际行来检查它是否是最后一行:

$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
}

You can check if it's the final row by checking the actual row against all rows:

$site2 = mysql_query("SELECT * FROM `sites` WHERE `user`='{$data->login}' ORDER BY `cpc` DESC");
$rows = mysql_num_rows($site2);
$i = 0;

And add this in your for loop:

$i++;
if($rows == $i) {
    // do something only at the final row
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文