我有一张名为 quest 的表:
id name
1 First Quest
2 Second Quest
3 Third Quest
4 Fourth Quest
5 Fifth Quest
6 Sixth Quest
7 Seventh Quest
8 Eighth Quest
9 Ninth Quest
10 Tenth Quest
11 Eleventh Quest
12 Twelfth Quest
和一个名为 current_quests 的表:
id user
5 motoc
在我的 quests.php 页面中,我打印了所有十二个任务并为每个任务分配了一个链接。对于第一个:localhost/quests.php?quest=1 对于第二个:localhost/quests.php?quest=2 等等...
因为在我的 current_quests 表中我有 id 5 我想在 quests.php 和 4,6 斜体中使 Fifth Quest 加粗。
First Quest
Second Quest
Third Quest
*Fourth Quest*
**Fifth Quest**
*Sixth Quest*
Seventh Quest
Eighth Quest
Ninth Quest
Tenth Quest
Eleventh Quest
Twelfth Quest
我想做什么,但我不知道当我在 current_quest 中插入另一个 id 时如何让我们说 id=6
id user
5 motoc
6 motoc
我要第五和第六变成粗体和 4 和 7 斜体
First Quest
Second Quest
Third Quest
*Fourth Quest*
**Fifth Quest**
**Sixth Quest**
*Seventh Quest*
Eighth Quest
Ninth Quest
Tenth Quest
Eleventh Quest
Twelfth Quest
这是我尝试过的,但我确信那很糟糕。
function SelectQuest($i){
$sth = $this->dbh->prepare("SELECT * FROM quests");
$sth->execute();
while($row = $sth->fetch(PDO::FETCH_ASSOC)){
switch ($row['id']) {
case $row['id'] == $i:
print "<a href='quests.php?quest=$row[id]'><b>$row[name]</b><br><br></a>";
break 1;
case $row['id'] == $i-1:
print "<a href='quests.php?quest=$row[id]'><i>$row[name]</i><br><br></a>";
break 1;
case $row['id'] == $i+1:
print "<a href='quests.php?quest=$row[id]'><i>$row[name]</i><br><br></a>";
break 1;
default:
print "<a href='quests.php?quest=$row[id]'>$row[name]<br><br></a>";
}
}
$sth = $dbh->prepare("SELECT * FROM current_quest");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
if (isset($_GET['quest'])) {
$item = $_GET['quest'];
print "string";
}elseif(isset($row['id'])){
$quest = new Quests($dbh);
$quest->SelectQuest($row['id']);
}
对不起,很长的帖子。这是我想要实现的图片。
谢谢