【发布时间】:2016-01-04 21:54:54
【问题描述】:
<?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% 确定你们会提出答案..提前致谢。
(注意:这是我的第二个问题,请原谅我的提问方式很尴尬)
【问题讨论】:
-
所以像标题一样做同样的事情。究竟是什么问题?
-
你能用我的代码示例写它吗...因为当我插入 ' .$title。 ' 像这样在 $outputListdata1 然后它显示错误..你能理解吗?请帮助过这座桥