PHP + MySQL,无法在新标签中打开DB url [重复]

时间:2022-06-21 06:28:05

This question already has an answer here:

这个问题在这里已有答案:

and first off a thank you to all of the * users as I have found a lot of good answers here. I am a PHP/mySql newbie and I’m teaching myself from books and examples from others.

首先感谢所有*用户,因为我在这里找到了很多好的答案。我是一个PHP / mySql新手,我从书本和其他人的例子中自学。

My problem: I have a mySQL DB with a URL column and a text column with a “clickme_text”, all the same DB row. From my website I want to be able to hit the “clickme” and then the DB URL will open in a new tab. Right now my PHP code works but it will not open the url in a new tab, it opens the new url in the same tab. I’m sure the answer is already out there somewhere, but I’ve gone crossed eye’d trying to create the html and PHP to both go to the new url and open in a new tab.

我的问题:我有一个带有URL列的mySQL数据库和一个带有“clickme_text”的文本列,所有相同的数据库行。在我的网站上,我希望能够点击“clickme”,然后数据库URL将在新标签页中打开。现在我的PHP代码可以正常工作,但它不会在新标签页中打开网址,它会在同一个标​​签页中打开新的网址。我确定答案已经出现在某个地方,但我已经克服了尝试创建html和PHP以转到新网址并在新标签中打开。

My DB url is “picture_link” and my clickme text in the DB is “picture_text”.

我的数据库网址是“picture_link”,我在数据库中的clickme文本是“picture_text”。

This code pulls the url and the “clickme text just fine from my DB, but it opens the url in the same tab.

这段代码从我的数据库中提取网址和“clickme文本就好了”,但它会在同一个标​​签中打开网址。

echo '<li>' . '<a href="' . $row['picture_link'] . '">' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';

I’ve tried a bunch of variations of something like this but it’s a no-go:

我已经尝试了一些像这样的东西的变化,但这是一个禁忌:

Echo ("<script>  window.open(\""'<li>' . '<a href="' . $row['picture_link'] . '">' .   $row['picture_text'] . '</a>' . '</li>' . '"\");

I know this html will open a new tab to “google” (for example):

我知道这个html会打开一个新的标签来“google”(例如):

<a href="http://google.com" target="_blank">Click Me!</a>

Do I need to create a var that points to my DB url, and then point my html to this var?

我是否需要创建指向我的数据库URL的var,然后将我的html指向此var?

Any help on how to open my “clickme” DB url in a new tab is appreciated, thank you.

有关如何在新标签页中打开“clickme”数据库网址的任何帮助表示赞赏,谢谢。

3 个解决方案

#1


You need to add target="_blank" to your link.

您需要在链接中添加target =“_ blank”。

echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';

#2


Simply add target="_blank" to your generated link:

只需将target =“_ blank”添加到生成的链接:

echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';

#3


Ted,

You just need to add the target to your tag

您只需将目标添加到标记中即可

echo '<li>' . '<a href="' . $row['picture_link'] . '" target=_blank>' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';

#1


You need to add target="_blank" to your link.

您需要在链接中添加target =“_ blank”。

echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';

#2


Simply add target="_blank" to your generated link:

只需将target =“_ blank”添加到生成的链接:

echo '<li>' . '<a target="_blank" href="' . $row['picture_link'] . '">' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';

#3


Ted,

You just need to add the target to your tag

您只需将目标添加到标记中即可

echo '<li>' . '<a href="' . $row['picture_link'] . '" target=_blank>' .   $row['picture_text'] . '</a>' . '</li>' . '<br/>';