Results 1 to 5 of 5
Thread: Simple MySQL Question
-
09-01-2003, 05:23 PM #1WHT Addict
- Join Date
- Apr 2002
- Location
- Cube Galaxy HQ
- Posts
- 104
Simple MySQL Question
If I want to use SELECT to get the last 10 entries of a database, what would I do?
:-D
-
09-01-2003, 05:46 PM #2Retired Moderator
- Join Date
- Apr 2003
- Location
- London, UK
- Posts
- 4,721
SELECT 'item' FROM 'table' ORDER BY id DESC LIMIT 10
Hyperconfused (™)
-
09-01-2003, 06:23 PM #3WHT Addict
- Join Date
- Apr 2002
- Location
- Cube Galaxy HQ
- Posts
- 104
Is there anything wrong with this code:
PHP Code:<?php
include("includes/database.php"); // connects to database
print("<html><body>");
$query = "SELECT * FROM site_news ORDER BY ID DESC LIMIT 10";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
print($row['body'] . "<br /><br />");
}
print("</body></html>");
?>
I get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site141/fst/var/www/html/db_test1.php on line 6:-D
-
09-01-2003, 07:36 PM #4Web Hosting Master
- Join Date
- Apr 2003
- Location
- Los Angeles, CA
- Posts
- 820
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
It looks like the query failed; check mysql_error(). Perhaps you don't have an column named ID in your site_news table?
-
09-01-2003, 11:45 PM #5Web Hosting Master
- Join Date
- Aug 2002
- Location
- Southwest Michigan
- Posts
- 935
PHP Code:<?php
include("includes/database.php"); // connects to database
print("<html><body>");
$result = mysql_query("SELECT * FROM site_news ORDER BY ID DESC LIMIT 10") or die("Error in statement! ".mysql_error());
while($row = mysql_fetch_array($result))
{
print($row['body'] . "<br /><br />");
}
print("</body></html>");
?>