Number of comments to show on a page in GBook version 1.7

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
uknowirock
Posts: 3
Joined: Sat Aug 22, 2009 3:57 am

Number of comments to show on a page in GBook version 1.7

Post by uknowirock »

Script URL:
Version of script: 1.7
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: limiting comments, comments on page

Write your message below:

While 10 is a good number of comments to show on a page, I have a project that requires me to lower that to 5

Is this done in gbook.php still? Anybody know the line number off hand?

If it's not done in gbook.php, I am way off, which file would it be in?

Thanks
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

Hello uknowirock,

Not done in GBook version 1.7.
But easily done because the solution of the previous version works also here.

So here it goes.

Number of entries per page modification for GBook version 1.7

Open file gbook.php
Find lines 147-167

Code: Select all

{
    $start = ($page*10)-9;
    $end   = $start+9;
}
else
{
    $page  = 1;
    $start = 1;
    $end   = 10;
}

$lines = file($settings['logfile']);
$total = count($lines);

if ($total > 0)
{
    if ($end > $total)
    {
    	$end = $total;
    }
    $pages = ceil($total/10);

and replace it with

Code: Select all

/* Number of entries per page modification by Henrie */	
{
    $start=($page*$settings['entries_page'])-($settings['entries_page']-1);
	 $end=$start+($settings['entries_page']-1);
}
else
{
    $page  = 1;
    $start = 1;
    $end=$settings['entries_page'];
}

$lines = file($settings['logfile']);
$total = count($lines);

if ($total > 0)
{
    if ($end > $total)
    {
    	$end = $total;
    }
    $pages = ceil($total/$settings['entries_page']);
/* End of number of entries per page modification by Henrie */
save and close the gbook.php file

Open the settings.php file
Before the /* DO NOT EDIT BELOW */ part add

Code: Select all

/* Number of entries per page modification by Henrie */	
/* Number of guestbook entries to be shown on each page */
$settings['entries_page']=5;
save and close the settings.php file.

Now you should be able to set the number of entries per page to whatever you like by changing the value in the settings.php file.

Greetings,
Henrie

PS. I changed the title of your post to a more meaningfull title. I hope this is okay with you.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

Thanks for sharing Henrie... something I forgot to add to 1.7, will be in 1.8.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

Okay Klemen, it is not so big a deal.
But a handy one if added.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
uknowirock
Posts: 3
Joined: Sat Aug 22, 2009 3:57 am

Post by uknowirock »

Thanks, I thought I had done it in previous versions. Thats not a tough fix.

No issues with the title either, it makes it so others can understand what I was trying to do
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

yes, so others can find it quicker if they want the same change.
And don't have to ask the question again.
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Hawk
Posts: 7
Joined: Sat Mar 03, 2007 8:16 am

Re: Number of comments to show on a page in GBook version 1.

Post by Hawk »

This is interesting. I did this and it seems to work fine.

Code: Select all

{
    $start = ($page*5)-4;
    $end   = $start+4;
}
else
{
    $page  = 1;
    $start = 1;
    $end   = 5;
}

$lines = file($settings['logfile']);
$total = count($lines);
Is this going to cause a problem?

You can see the Guestbook I did this with at this link: http://artsbagelsandmore.com/gb/gbook.php
[size=100][i]Hawk[/i][/size]
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Re: Number of comments to show on a page in GBook version 1.

Post by Henrie »

If you have not changed this

Code: Select all

$pages = ceil($total/10);
to

Code: Select all

$pages = ceil($total/5);
a few lines further in the code, you will now be missing half the pages of entries.

And my code might be harder to do, but it is more flexible for all users and future changes.

Greetings,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Hawk
Posts: 7
Joined: Sat Mar 03, 2007 8:16 am

Re: Number of comments to show on a page in GBook version 1.

Post by Hawk »

Yes, I did also make that change.

It's not that your code is hard to do. I made my edits before I saw this thread.

If your changes would be better, it's not a problem for me to make those edits.
Looking at your edits, I see where it would be better. Thank you! :)

I'd buy you a bear but I can't even afford to buy myself one right now. :(
[size=100][i]Hawk[/i][/size]
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Re: Number of comments to show on a page in GBook version 1.

Post by Henrie »

Not a problem that you do not buy me a drink. That you are thinking about it is good enough for me :)

Greetings,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Post Reply