Reputation: 107
I am having a problem retrieveing information from a MySQL Data Base. Could you help me out? This is the code I wrote:
<?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 }; ?>
Nothing inside the SELECT notas database is showing. It is simply gone...
Thanks!
Upvotes: 2
Views: 186
Reputation: 360572
The other answers above have it correct - you've got a syntax error in your query. If you'd done the basic step of having:
$result = mysql_query(..) or die(mysql_error());
you'd have seen the error message. Never EVER assume that a query succeeds. Always check for error conditions.
As well, you've got a minor syntax bug in your output:
... <a href="/nota/<?php echo $nt[fecha]."/".$nt[titulolower] ?>"> ...
^^^^^
Your array keys are not quoted, which means they're interpreted as define()
'd constants. PHP is polite and will treat those constants as strings if there actually is not constant with that name, but it will issue a warning for every occurence. It should be:
<?php echo $nt['fecha'] ... ?>
Upvotes: 0
Reputation: 10214
what does the error message say
$result = mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC");
if (mysql_error()) {
die(mysql_error());
}
Upvotes: 0
Reputation: 4740
I don't too well about PHP, but your select statement limits to just one result. You might want to change this line:
$result = mysql_query("SELECT * FROM notas LIMIT 1 ORDER BY id DESC");
You will not get more than one result as it is.
Upvotes: -1