Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2007-09-24, 11:08 PM
Junior Member
 
Join Date: Jan 2007
Posts: 12
Wilson is on a distinguished road
Default A Simple Select Question

I have a Select statement that I want to show only the last 100 records of the database as they are added on an ongoing basis. How do I write the statement? This is my current code. Of course this way i will have to constantly update the > 100 element

Code:
$sql = 'SELECT * FROM `enter` WHERE `id` > 100 ORDER BY `id` ASC';
$result = mysql_query($sql, $dbh)
OR die ($sql . mysql_error());
$count= mysql_num_rows($result);
echo ("<table border='1'>");
echo "<th>ID</th>
      <th>IP Address</th>
      <th>Date - Time</th>
      <th>Page</th>";
WHILE (LIST($id, $address, $date, $page) = mysql_fetch_array($result))
{
echo "<tr>\n" .
"<td>$id</td>\n" .
"<td>$address</td>\n" .
"<td>$date</td>\n" .
"<td>$page</td>\n" .
"</tr>\n";
}
echo "</table>";
?></p>
Thank you
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2007-09-25, 06:06 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,104
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

SELECT * FROM `enter` ORDER BY `id` desc limit 100;

Basically what we are doing here is telling it to get all the results, but order them in descending order by the id, so largest first, and then limit the results to only the first 100 records returned, i.e. the 100 records with the largest IDs.
__________________
I rarely give code examples.
No, I have never used IIS or Windows of any kind as a web server. Get a real OS!
Please don't PM me, I won't respond.
Reply With Quote
  #3 (permalink)  
Old 2007-09-25, 05:31 PM
Junior Member
 
Join Date: Jan 2007
Posts: 12
Wilson is on a distinguished road
Default

OMG, what was I thinking. I should have seen that a mile away. I tried everything under the sun.

thank you very much friend.
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.0 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.0 (a popular PHP IDE) and NuCoder 1.4 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:55 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.