CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Getting the next set up messages

 



darian
Deleted

Feb 10, 2000, 3:12 AM

Post #1 of 3 (738 views)
Getting the next set up messages Can't Post

Ok I have a way to list my messages from the last to the first with 10 at a time. What I need to figure out now is how to get the next set up 10 until there are no more. I have posted the code below to show you basically what I have so far. This works great except I can't seem to figure out the code to get the rest of the messages past the first ten. I could simply change the number listed (10 in this case) but I want to have it set to a limit to keep from having to scroll down the screen 100 times to see them all. Thanks.


if ($lastMsg == "") { $lastMsg = $count };

for ($c=$lastMsg; $c >= 1 && $c> $lastMsg-10; $c--) {

##display code


}



japhy
Enthusiast

Feb 10, 2000, 4:02 AM

Post #2 of 3 (738 views)
Re: Getting the next set up messages [In reply to] Can't Post

What you want to do is, after you've shown 10 messages (or whatever), the "Next 10" link (or button) should send the program a parameter saying where it left off:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


use CGI;
$q = new CGI;
$last = $q->param('last_msg') | | $num_of_msgs;

print << "END";
Content-type: text/html

<html>
<body>
END

for ($i = $last; $i && $i > $last - 10; $i--) {
print $messages[$i];
}

$last--;

print << "END";
<a href="thisprogram.cgi?last=$last">Next 10</a>
</body>
</html>
END
</pre><HR></BLOCKQUOTE>

[This message has been edited by japhy (edited 02-10-2000).]


RayStreet
Deleted

Feb 10, 2000, 1:23 PM

Post #3 of 3 (738 views)
Re: Getting the next set up messages [In reply to] Can't Post

You could put multiple page hyperlinks at the bottom of the page which allows jumping around the messages. You should know how many messages are in the array ($count = @messages + 0). And you know how many messages you want on a page (10) so something like this:-

$pagesize = 10;
$pgcount = int($count / $pagesize);
if (($pgcount * $pagesize) != $count) {
$pgcount++;
}

So $pgcount has the maximum number of pages.

At the foot of your html page do something like this:-

$pagelinks = " ";
$pageno = 0;
if ($pgcount > 1) {
while ($pageno < $pgcount) {
$pageno++;
$thislink = " <a href=\"http://domain/cgi-bin/xxx.cgi?page=$pageno&pagesize=$pagesize\">" . $pageno . "</a>";
$pagelinks = $pagelinks . $thislink;
}
}

Then print $pagelinks to show all of the stiff on the page.

So when someone clicks on the link they are passed to the xxx.cgi script (which could be the same script your in - doesn't matter) and you know the page number that is needed - just subtract 1 from this and multiply the result by $pagesize and then add 1 and you know the next message number to show.

If you use a variable like $pagesize instead of hard-coding "10" then you can experiment on how many messages to show on a page more easily by just having to change one line of code.

I've used this technique a couple of times and it's very simple and effective.

Have fun.

Ray

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives