【发布时间】:2011-10-19 20:15:53
【问题描述】:
我在从 MySQL 数据库检索信息时遇到问题。你能帮帮我吗?这是我写的代码:
<?php
$result = mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC");
while($nt = mysql_fetch_array($result)) {
?>
<div class="nuevos_1">
<div class="over_descripcion">
<div class="over_title">
<h3><a href="/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>"><?php echo $nt[titulo] ?></a></h3>
</div>
<div class="over_autor">
<span><b>Por: </b><a href="/autor/<?php print $nt[autor]; ?>"><?php print ucwords(str_replace("-", " ", $nt[autor])); ?></a> <?php echo $nt[fecha] ?></span>
</div>
<div class="over_texto">
<span><b><?php echo strtoupper(str_replace("-", " ", $nt[categoria])) ?></b> <a href="/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>"><?php echo substr(strip_tags($nt[texto]), 0, 240)."..." ?></a></span>
</div>
<div class="over_ver_mas">
<input type="button" value="Leer más" onclick="location.href='/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>'" />
</div>
</div>
<a href="/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>">
<img src="http://<?php echo $nt[imagen] ?>" border="0" />
</a>
</div>
<?php }; ?>
SELECT notas 数据库中没有显示任何内容。简直没了……
谢谢!
【问题讨论】:
-
你需要先打开一个连接。 mysql_connect(...);你有这个吗?
-
以后暂时做
mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC") or die(mysql_error());看看报错信息是什么。这将帮助您修复它。然后删除or die... 部分,因为它可以泄露敏感信息。您可以做的另一件事是安装phpMyAdmin 并在那里运行您的查询。这也会显示错误。 -
我想指出您正在以不受支持(已弃用)的方式访问 $nt[] 数组。而不是使用 $nt[index] ,你应该使用 $nt['index'] 。