gpt4 book ai didi

php - 如何在 href 中插入 php 变量以从该变量的检索结果创建链接?

转载 作者:行者123 更新时间:2023-11-29 04:41:24 24 4
gpt4 key购买 nike

<?php
mysql_connect("localhost","username","password") or die (mysql_error());
mysql_select_db("databasename") or die (mysql_error());

$sqlmydata = mysql_query("SELECT id, label, title, info, body FROM table LIMIT 0,10");

// Build the Output Section Here
$outputListdata1 = '';
while($row = mysql_fetch_array($sqldata)){

$id = $row["id"];
$label = $row["label"];
$title = $row["title"];
$info = $row["info"];
$body = $row["body"];

$outputListdata1 .= '<div class="content1">
<a href= "#" >' .$title. '</a>
</div><!-- end of content1 -->

<div class="content2">
' .$info. '
</div><!-- end of content2 -->';
} // close while loop
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>my site</title>

</head>

<body>

<div class="container">
<?php print "$outputListdata1"; ?>
</div><!-- end of container -->

</body>
</html>

查看 $outputListdata1 中的第 14 行,其中 $title 位于 href 之间:

<a href="#" >' .$title. '</a>

我想在 href 中插入一个 $label 变量来代替 #。因此,它应该显示我的数据库中变量的结果。

<a href="$label" >' .$title. '</a>

例如:

如果我的数据库有 $label 变量的结果是 karthik 意味着那么它应该看起来像(考虑变量 $title 的结果作为堆栈溢出的粉丝),

<a href="karthik" > fan of stack overflow</a>

我知道我的问题可能很简单也可能很棘手,但我 100% 确定你们会给出答案..在此先感谢。

(注意:这是我的第二个问题所以请原谅我的提问方式很尴尬)

最佳答案

您可以编写符合 HTML 的 php,使用 echo 命令可以将变量/字符串输出到将发送给用户的 HTML 中

<a href="<?php echo $var1; ?>" > <?php echo $var2; ?></a>

关于php - 如何在 href 中插入 php 变量以从该变量的检索结果创建链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27954737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com