Php 在html标记中进行回显
PHP只在我直接用HTML标记回显内容时才起作用(Php 在html标记中进行回显,php,Php,PHP只在我直接用HTML标记回显内容时才起作用(echo在标记之外),如下所示 include('db.php'); $blogurl="http://www.com/view/"; $results = mysql_query("SELECT * FROM product ORDER BY `id` DESC LIMIT 1"); while ($row = mysql_fetch_array($results)) { echo "<h2><a href=" . $blog
echo
在标记之外),如下所示
include('db.php');
$blogurl="http://www.com/view/";
$results = mysql_query("SELECT * FROM product ORDER BY `id` DESC LIMIT 1");
while ($row = mysql_fetch_array($results)) {
echo "<h2><a href=" . $blogurl . $row['url'] . ">" . $row['title'] . "</a></h2>";
include('db.php');
$blogurl=”http://www.com/view/";
$results=mysql_查询(“按`id`DESC LIMIT 1'从产品订单中选择*);
while($row=mysql\u fetch\u数组($results)){
回声“;
}
但当我尝试这种风格时,它不起作用:
<?php
include('db.php');
$results = mysql_query("SELECT * FROM product ORDER BY `id` ASC");
while ($row = mysql_fetch_array($results)) {
$blogurl="http://www.com/view";
$url=$row['url'];
$title=$row['title'];
?>
<td>
<a href="<?php echo $blogurl;?>/<?php echo $url;?>"><?php echo $title;?></a>
</td>
<?php
}
?>
我想要的是改变从数据库回显数据的方式。但第二种风格有什么问题 代码应为:
<?php
include('db.php');
$results = mysql_query("SELECT * FROM product ORDER BY `id` ASC");
$blogurl="http://www.com/view";
while ($row = mysql_fetch_array($results)) {
$url=$row['url'];
?>
<td><a href="<?php echo $blogurl;?>/<?php echo $url;?>"><?php echo $title; ?></a></td>
<?php
}
?>
试试这个
<?php
include('db.php');
$blogurl="http://www.com/view";
$results = mysql_query("SELECT * FROM product ORDER BY `id` DESC LIMIT 1");
while ($row = mysql_fetch_array($results)) {
echo "<h2><a href='" . $blogurl."/".$row['url'] . "'>" . $row['title'] . "</a></h2>";
}
?>
试试这段代码
<?php
include('db.php');
$results = mysql_query("SELECT * FROM product ORDER BY `id` ASC");
$blogurl="http://www.com/view";
while ($row = mysql_fetch_array($results)) {
$url=$row['url'];
$title=$row['title'];
?>
<td><a href="<?php echo $blogurl.'/'. $url;?>"><?= $title;?></a></td>
<?php
}
?>
我刚刚解决了它。我认为问题是因为我们无法从数据库中获取具有html扩展的内容。因此,解决方案是,我必须创建一个字符串或变量,或者(我不知道我们在php中如何称呼它),如下所示:
/
解决方案是我不需要数据库中的url行。我只需要回显标题,并在后面加上“.html”
谢谢所有帮助过我的人
为这样一个问题干杯,代码中缺少分号。您可以用于语法错误检查…请发布生成的HTML。你使用的是有效的html吗?我的意思是你应该学会调试你的代码!!逻辑错误,坏习惯。。你是另一回事!!为什么其他人要修复您的语法错误和打字错误:)例如,混合视图代码和数据库模型)代码不是一件好事!,你最终会得到重复的、不可维护的代码,这是行不通的。我唯一知道的是问题来自