Limiting While Loops

This is a discussion on "Limiting While Loops" within the Databases section. This forum, and the thread "Limiting While Loops are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jul 8th, 2007, 16:34
Up'n'Coming Member
Join Date: Feb 2007
Location: United States
Age: 15
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Limiting While Loops

Ok Webforumz, I need help... I'm a little stuck... Can anyone help me figure out how to use a while loop and limit the amount of rows of data it outputs? Basically, display the last 3 or so entries.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 8th, 2007, 20:51
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Limiting While Loops

umm, some code might help. Which programming language are we using?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 10th, 2007, 18:42
Up'n'Coming Member
Join Date: Feb 2007
Location: United States
Age: 15
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Limiting While Loops

oops, forgot. PHP is what I'm using. The point is I'm trying to see if there is a code for it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 10th, 2007, 18:48
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Limiting While Loops

Shouldn't you be doing that in your sql query?

Something like

PHP: Select all

$GetLast3 mysql_query("select * from table order by id desc limit 3"); 

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 10th, 2007, 20:44
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Limiting While Loops

ummm. The while loop is the limit for how many lines of data get output:
PHP: Select all

$i=0;
while(
$i 3) {
  
// output stuff
  
$i++;

but actually a for loop is better for something like that:
PHP: Select all

for($i=0;$i<3;$i++) {
  
// output stuff

I hope I'm understanding your question right.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jul 12th, 2007, 04:33
Up'n'Coming Member
Join Date: Feb 2007
Location: United States
Age: 15
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Limiting While Loops

Thanks for all the help everyone
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
loop, mysql, while

Thread Tools

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Logic Problem involving loops and arrays tox0tes Other Programming Languages 5 Oct 28th, 2007 03:11
Free Flash music and ambient loops equinoxsounds Flash & Multimedia Forum 3 Oct 12th, 2007 09:57
Limiting a while loop? Weird1993 Databases 1 May 10th, 2007 19:51
Limiting Users Files in a Database... JohnMitch Classic ASP 3 May 13th, 2005 15:30
while loops? mikegu JavaScript Forum 1 Oct 26th, 2003 11:08


All times are GMT. The time now is 22:00.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42