Php 如何打印一次超链接?
这些是我的桌子: 1.主题表格:Php 如何打印一次超链接?,php,Php,这些是我的桌子: 1.主题表格: topic_id subject 1 bla bla 2 two two content_id topic_id content date 1 1 subject descriptio
topic_id subject
1 bla bla
2 two two
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
2目录表格:
topic_id subject
1 bla bla
2 two two
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
如您所见,内容表中的topic\u id
是topics表的外键。目录表中的content
列存储主题的描述/内容(topic#id#1,例如)以及典型主题#id#1的回复(content#id#2,#3)。因此,为了打印出主题
一次,我编写如下代码:
$printsubjectonce = FALSE; // Flag variable.
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
if (!$printsubjectonce) {
echo "{$row['subject']}\n"; //subject is printed ONCE
$printsubjectonce = TRUE;
}
//print the content:
echo "{$row['content']} <br />({$row['date']}\n"; //The subject description and possible repli(es) are repeatedly printed
}// End of WHILE loop.
$printsubjectonce=FALSE;//标志变量。
而($row=mysqli\u fetch\u数组($r,mysqli\u ASSOC)){
如果(!$PrintSubjection){
echo“{$row['subject']}\n”//主题打印一次
$printSubjection=TRUE;
}
//打印内容:
echo“{$row['content']}
({$row['date']}\n”//重复打印主题描述和可能的回复
}//WHILE循环结束。
一切正常。现在我想在主题内容下方添加一个删除超链接,但不在主题行下方。然后,我在$row['content']
下方添加
。但是,输出显示删除超链接根据可能的回复数量重复打印出来主题得到了。然而,我希望仅打印一次超链接(主题描述下方),无论主题有多少回复
我还尝试将移动到
if(!$printSubjection){…}',就在代码$printSubjection=TRUE;
的上方,然后在内容部分的上方按逻辑打印出来,我不想这样做
我现在被困在这里了。你能帮我吗?试试用这样的东西
<?php
if (!defined('CODE_EXECUTED')) {
YOUR_CODE_HERE
define('CODE_EXECUTED', TRUE);
}
?>
然后,您可以将“删除”按钮放在任何您喜欢的地方;您可以使用类似的方式打印“删除”按钮一次:
echo "{$row['content']}" . ((!defined('delButton'))?"<a href='delete.com'> Delete </a>":"") . " <br />({$row['date']}\n";
define('delButton', TRUE);
echo“{$row['content']}.”((!defined('delButton'))?”“:”“)。“
({$row['date']}\n”;
定义('delButton',TRUE);
这将使删除按钮打印一次。测试它。使用两个if
语句。第一个用于打印主题标题,第二个用于打印删除链接。将$printSubjection=true
赋值放在第二个之后
$printsubjectonce = FALSE; // Flag variable.
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
// Print subject header once
if (!$printsubjectonce) {
echo "{$row['subject']}\n";
}
//print the content:
echo "{$row['content']} <br />({$row['date']}\n"; //The subject description and possible repli(es) are repeatedly printed
// Print delete link once
if (!$printsubjectonce) {
echo '<a href="delete.com"> Delete </a>';
$printsubjectonce = TRUE;
}
}// End of WHILE loop.
$printsubjectonce=FALSE;//标志变量。
而($row=mysqli\u fetch\u数组($r,mysqli\u ASSOC)){
//打印主题标题一次
如果(!$PrintSubjection){
回显“{$row['subject']}\n”;
}
//打印内容:
echo“{$row['content']}
({$row['date']}\n”//重复打印主题描述和可能的回复
//打印删除链接一次
如果(!$PrintSubjection){
回声';
$printSubjection=TRUE;
}
}//WHILE循环结束。