dongyue3795 2014-08-05 05:26
浏览 42
已采纳

如何打印超链接ONCE?

These are my tables:

1.topics table:

topic_id            subject         
   1                 bla bla      
   2                 two two       

2 contents table:

content_id          topic_id        content                     date
   1                   1             subject description       7/10/2014
   2                   1             reply1                    7/12/2014
   3                   1             reply2                    8/1/2014

As you can see, the topic_id in the content table is the foreign key of the topics table. The content column in the contents table store the description/ content of the topic (topic_id # 1, for instance) as well as the repli(es) (content_ids # 2, #3) of the typical topic_id #1 too. So, in order to print out the subject once, I code like this:

$printsubjectonce = FALSE; // Flag variable.

while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {

    if (!$printsubjectonce) {

    echo "{$row['subject']}
"; //subject is printed ONCE

         $printsubjectonce = TRUE;

    }

    //print the content:
    echo "{$row['content']} <br />({$row['date']}
"; //The subject description and possible repli(es) are repeatedly printed

}// End of WHILE loop.

Everything is okay. Now I would like to add a delete hyperlink below the subject content, but not below the subject line. Then, I add <a href="delete.com"> Delete </a> below the $row['content']. However, the output shows that the delete hyperlink(s) is/are repeatedly printed out in according with the possible number of repli(es) the subject has got. However, what I wish is to have the hyperlink printed out only once (below the subject description) in spite of how many repli(es) the subject would have.

I also tried moving the <a href=...> into theif (!$printsubjectonce){...}', just above the code $printsubjectonce = TRUE;, it is then logically printed out above the content section, which i didn't want to.

And I got stuck here now. Can you help me?

  • 写回答

2条回答 默认 最新

  • doumao1917 2014-08-05 05:30
    关注

    Try using something like this;

    <?php
    
    if (!defined('CODE_EXECUTED')) {
        YOUR_CODE_HERE
        define('CODE_EXECUTED', TRUE);
    }
    
    ?>
    

    You can then place the delete button where ever you like; you can use something like this to print the delete button once:

     echo "{$row['content']}" . ((!defined('delButton'))?"<a href='delete.com'> Delete </a>":"") . " <br />({$row['date']}
    ";
     define('delButton', TRUE);
    

    That will make the delete button print out once, supposedly. test it out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能