We help IT Professionals succeed at work.

I have a for loop that is echoing values out of the database, anyway to pause in-between listings?

stormist
stormist asked
on
Medium Priority
252 Views
Last Modified: 2008-03-10
Each loop echos about a 3 sentence entry. The problem is it sometimes just fills the screen with them. I'd like to list each one at a time, followed by a "click here to continue" or similiar statement, then show the next one in the loop. Is that possible?

Comment
Watch Question

CERTIFIED EXPERT
Commented:
There's no way to pause the loop in the middle of its execution and get user input.  You could either load all of the content into the page and then hide/display it (perhaps with a javascript), or use a paging technique to display a link below the current entry that the user could click to reload the page and display the next one (which would involve a new query every time).

It sounds like the best option would be to just break your database query results up using paging techniques and load a certain number of entries at a time (however many you think is an acceptable amount to display at once).  This would still require a database query for every page of entries that the user views, but it would be more efficient than pulling them one at a time.

Hope that helps give you some idea of what to do :)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I'm up for learning Javascript soon(ive actually got the books ordered) but for now I really don't know it very well. The hiding idea and revealing when they click sounds really cool. Would it be complicated to code and explain? :)

(hi again tomeeboy. Man between you, Roonan, and Bogo I get most of my problems solved! :) )
CERTIFIED EXPERT

Commented:
For the javascript show/hide method, I think you'd need to put the content in seperate divs that would have unique id names:

<div id="one"> Your Content </div>
<div id="two" style="display:none"> Your Content #2</div>

Here's some javascript I came across for showing/hiding one or more divs based on their ID:

<script type="text/javascript">

function show()
{
for(var I=0;I<arguments.length;I++)
{
var obj=document.getElementById(arguments[I]);
obj.style.display = '';

}
}
function hide()
{
for(var I=0;I<arguments.length;I++)
{
var obj=document.getElementById(arguments[I]);
obj.style.display = 'none';

}
}
</script>

So your link might look like this:

<a href="#" onClick="hide('one');show('two')">Show Item #2</a>

Haven't tested this for accuracy... it's very late :)  Hopefully gives you some ideas though.
CERTIFIED EXPERT

Commented:
I still think the paging option would be better, as the javascript method could essentially end up hiding all of your content from somebody who had javascript disabled :)

Author

Commented:
Thx! :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.