|
It is currently Fri Sep 20, 2024 5:56 pm
|
|
Page 1 of 1
|
[ 12 posts ] |
|
Author |
Message |
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16661 Location: On a slope
|
PHP and Mysql
heh...not phpbb, just php...anyway...
ok, so I created a table. There are a number of records, and each has a number of fields including date.
What's the best way to return only the ten most recent entries? Or at least only print out the ten most recent. I'm mildly stumped.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Tue May 04, 2004 5:27 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16661 Location: On a slope
|
Nevermind, I've discovered the wonders of $num_rows.
I've written this and it seems to work. Any suggestions for improvement or whatever would be greatly appreciated.
| | | | Code: $max=10; $select = "SELECT * FROM clankiller_news ORDER BY 'date' ASC"; mysql_select_db("luciferia",$db); $result = mysql_query("$select",$db); $num_rows = mysql_num_rows($result);
$i = $num_rows;
while ($i >= $num_rows - $max){ $i--; printf("<br>key: %s", mysql_result($result,$i,"key")); printf("<br>date: %s", mysql_result($result,$i,"date")); printf("<br>author: %s", mysql_result($result,$i,"author")); printf("<br>news: %s", mysql_result($result,$i,"news_item")); printf("<br><br>"); }
| | | | |
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Tue May 04, 2004 8:43 pm |
|
|
Manuel
|
Clankiller News
Tweeking your code:
SELECT * FROM clankiller_news ORDER BY 'date' ASC LIMIT 10
|
Tue May 25, 2004 8:39 am |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
Wow, may 5th. Never saw this post. Yeah, limit 10 is a better way to go. It's also part of pagination if you ever decide to get crazy.
|
Tue May 25, 2004 12:32 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16661 Location: On a slope
|
ah, yes, I've come quite a bit further since then. What were you saying about pagination? Anyway, the stuff I'm having issues with now is too long to post. heheheh.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Tue May 25, 2004 5:32 pm |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
Yes, I'm sure your shrink has reams about the help you need...
Pagination is having your results split up onto multiple pages, like these forums.
|
Tue May 25, 2004 7:06 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16661 Location: On a slope
|
ah, I understand. I don't plan on doing that with my timecard thing. I've already gotten the reporting function to work, which can get onbovious if you choose a really huge timeframe. But blah, it's only for 2 users.
I'm reworking the code on that now. Having issues making it function if lunches aren't taken. But I'll sort it. BTW, I have a love/hate relationship with Unix time.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Wed May 26, 2004 8:36 pm |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
??? unix timestamps are the shizzle!!!! Blasphemer. Did you read my tut on working with unix timestamps?
http://www.webhead.cc/main.php?inv=59
|
Wed May 26, 2004 9:53 pm |
|
|
RB
Emperor
Joined: Wed Apr 16, 2003 1:25 am Posts: 2560
|
Heheh, Pig. You can fix that background imaged code. It would look better if it don't move with scrolls. Just my opinion, of course.
{...
background-image:url('whatIknow.hell');background-attachment: fixed;
...}
_________________ ++
|
Thu May 27, 2004 8:31 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16661 Location: On a slope
|
hah...I didn't realize you wrote a tut.
I just read through it... I'm afraid that I already figured out most of that. Or all of it. btw, why no mention of mktime()? EH?! heh. I use it to figure out the unix timestamp of today (ie, mktime(0,0,0);). I guess time() is close enough.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu May 27, 2004 8:48 am |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
mktime is retarded in comparison to strtotime(). I honestly can't think of a need for mktime.
|
Thu May 27, 2004 12:32 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16661 Location: On a slope
|
mktime is a quick and easy way of finding out today at midnight. It's so quick. I use strtotime for virtually everything else, though, so you're correct in most instances.
btw, I finally figured out how to do the no lunch thing. I can't believe I beat my head against a wall for several days for 17 lines of code. Which I coulda squished down into like 9 lines if I really wanted to.
Blah, anyway, I'm proud, I finally got the hard part. Now for the rest.
_________________ They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.
|
Thu May 27, 2004 5:02 pm |
|
|
|
Page 1 of 1
|
[ 12 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|