pagnation - but I have read the tutorials

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RampantGiraffe
Forum Newbie
Posts: 6
Joined: Sat Mar 11, 2006 4:39 pm

pagnation - but I have read the tutorials

Post by RampantGiraffe »

Ok. As this is a theorectical question it can be posted here. I have trawled countless forums and tutorials on various websites here, phpbuilder, phpfreaks etc and I can't really seem to find an answer to my problem. Maybe they just haven't been explained in a way I understand yet. :/

I have already paginated my results pulled from MySQL database... it was easy I copied the tutorial in the book (I'm sure there is a better way of writing it but I'll go back and look at that when I'm a bit more proficient).

I am pulling records from MySQL database which are articles with some images included. The articles are of various lengths and the images various sizes. As the result of this limiting to 5 records per page has different results depending on which articles are to be displayed.

Page 1 currently has a lot of space at the bottom of the page as the articles displayed here are quite short. Page 2 has large articles and overshoots the bottom of my page template causing the /div its posted in to continue on past the bottom of the rest of my page.

Is there a way of limiting results based on total number of characters contained in a specific field (if I establish how many characters could fit on the page to begin with)instead of just limiting by number of rows returned?

Or is it possible to create (from the query results) a page height variable that can be posted to the other parts of my web page so that the rest of the site fits the results.

If either is possible which would be the better of the two? If not any suggestions with how to deal with this? Any links to resources which might give me ideas on where to start with the coding would also be appreciated.

Thanks
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

Not an answer to your actual question, but would it be acceptable to set the style of your article div to "overflow:auto;" so that when it exceeds the template height it brings in scrollbars instead?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

That's exactly what I thought, just add vertical scrollbars to your layout so it wont stretch anything.

What you're actually asking can be done ofcourse, I don't personally know if/how you can count characters via an SQL statement, so I would put forward you fetch the total amount of characters in every article in your table, then divide it by the amount you want per page, and round it to the nearest complete article.

Perhaps it would be easier/make more sense if you limited the words per page rather than the characters.
RampantGiraffe
Forum Newbie
Posts: 6
Joined: Sat Mar 11, 2006 4:39 pm

Post by RampantGiraffe »

Was hoping to avoid scroll bars (as the content goes in the centre pane with a nav bar either side) but it may have to be the way forward for the time being.

If anyone has any inspired ideas re: other methods please post back.
Cheers
RG
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

It seems to be a styling issue rather than anything else. DIV's generally expand themselves to fit content - so unless you have a parent div with a fixed height or position this is generally not an issue. Maybe you could try posting an excerpt of your html and css style to one of the other forums? Might be of some help.
RampantGiraffe
Forum Newbie
Posts: 6
Joined: Sat Mar 11, 2006 4:39 pm

Post by RampantGiraffe »

Decided to stop torturing myself and just chop the text with links to the full article.

This should probably be moved to the Noob forum for my next question :)

Stupid questions but am I right in thinking that the substr function is just going to take into account the actual text in results.

So the way I have my site set up at the moment is that my article field will contain <img> tags in the relevant places around the article in amongst the text. Substr will only count the number of characters in the string and not pay any attention to the space the image will take up.


Thanks
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

substr() doesn't count anything. substr() returns a piece of a string between/from/to two specified points in a string.

Every character inside of the string will be taken into consideration.

If you want the size of the img tag parameters to not effect the length of the string, use regex to cut out the img tag before using substr.
Post Reply