Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting pages in one field 1

Status
Not open for further replies.

sinbadly

Technical User
Joined
Mar 16, 2006
Messages
126
Location
GB
I want to add the choice of splitting pages to the field 'story'. I'm using $myrow['field']s and displaying them with the printf() function.

I can't work out where to put the spliti function. Should it go within printf() for the 'story' $myrow field?

Some advice from PHP people who know would be appreciated very much.

. . . . . . . <my code>

printf(" %s\n<br>",

// Split the text into an array of pages
$textarray = spliti('\[PAGEBREAK]', $result);
// Select the page we want
$result = $textarray[$page];
$PHP_SELF = $_SERVER['PHP_SELF'];
if ($page != 0) {
$prevpage = $page - 1;
echo "<p><a href=\"$PHP_SELF?id=$id&amp;page=$prevpage\">".
'Previous Page</a></p>';
}
echo "<p>$b</p>";
if ($page < count($textarray) - 1) {
$nextpage = $page + 1;
echo "<p><a href=\"$PHP_SELF?id=$id&amp;page=$nextpage\">".
'Next Page</a></p>';
}
$myrow["story"]);
. . . . . .

You can probably see that it doesn't work this way. Help, please, Masters.
 
sajax aint a language. it's just a term for combining a backend process (like php) with javascript in a way that allows client-server interaction and avoids page refreshes. it basically just means you don't have to press submit...

don't be put off by my code - what i have done is split your single page into a variety of logically separate functions. you actual code has not changed much.

this is a very effective style of coding that, IMO, leads to good security practices (via a dispatch board - see the early switch statement) and a code reusability and ease of debugging.

in the above code - everything for display is assembled into a single variable ($contents) so the actual display bit is handled in a three lines
Code:
<div id="container">
<?=$contents?>
</div>
i use this style a lot for my coding. i keep a variety of templates with page structure and html in them and some php tags where i want content to go. i then populate the variables in php and then "require" the relevant html template. the template represents the output and all the tags are automatically replaced by their variable equivalents. the only thing you need to be careful about in this style is variable scope. sometimes i find that i have instantiated a variable in a particular function and then displayed the page in another function. using $GLOBALS can be helpful for this.

post back once you have played with the code. or email (this chain is getting long and so might be cut by the moderator). as said, i couldn't debug the code fully as i don't have your schema or any trial data.

Justin
 
All noted (and printed off), Justin, thanks very much. I dowloaded some info from zend about switch, and am trying to get that through the skull.

Yes, there are great things in your coding that are very new to me. Very grateful for the experience.

I went through the code last night and it was bringing up the first page well, but not the next ones. I hope to get more time tonight to concentrate on it. It looks very good, and I am much obliged. If the cut-off comes, I'll keep you up to date by email. Cheers, and gratitudes. paul
 
Actually, I can't email you, I see. There are no details on these tek-tip profiles.
 
i thought i posted my email in a previous post. anyway - reach me at jpadie [INSIDE] hotmail {POINT} COM.

on your previous post - does the second and subsequent pages appear if you are not using ajax?

i could help out more if you were able to give me a SQL create statement for your table and and few rows of sample data. phpmyadmin will do this for you. normally these errors are really minor but they are a b****r to find without sample data.
 
Hi Paul

i have created some dummy data and created a replica of bits of your site on one of my servers.

have a look at the code in working order at

there are links to turn ajax on and off.
also you can get the source code by clicking on the showsource link.

hope that was what you were after.

Justin
 
Justin - Rushing here, found this, and taking it away to look. I spent some time on it last night, but couldn't get it to quite do the thing. Will be very keen to see this. Thanks very much. Will report back ...
 
have fun! the code works for me (so far as i understand what you were after). do post back or email this evening (i'll be working late) if it doesn't do it for you.

 
Hi Justin

Once it gets to your server, then it looks brilliant. I think I grasp a lot of it, but I can see I'm not going to get there by rushing. Hope I'll get a chance to ponder this afternoon, or this evening. Very grateful for the trouble you have gone to, and hope the next time I report back, it will be more positive (from my side, I mean.) Gratefully, Justin
paul
 
i tweaked the code a little since the last post (hence why i put a download link on my server) - this may be why it doesn't look right on your servers.

glad to be (potentially) of help
justin
 
Hi Justin
I've missed this last message of yours, unfortunately. However, m u c h time has gone into it and I am almost there. I have borrowed bits from various suggestions of yours - for which I am very grateful - and now it's almost working. Well, it's working, but not everything works as it should - yet.

Plan to see your changes this afternoon, if I get the chance. Cheers, Justin, many thanks. paul
 
Hello Justin

Well, got to the end of it yesterday afternoon. I borrowed much of what you had suggested, and for which I am very grateful.

The answer to it all was that I didn't need to have separate codings with ifs or switches! I only discovered this in desperation, and because I couldn't think of anything else.

Of course, it is rather obvious. If an article contains the magic message [PAGEBREAK], the code splits it. If there isn't one in the text, the code just continues on its merry way.

It took a long time, and it was marvellous of you to help so well, to introduce me to switch and more, and also to sajax which I see being talked about quite a lot. Cheers and many thanks, Justin.

paul

I've copied all your suggestions, and will put them to use in the future, particularly when I am more familiar with the magic of php. Many thanks.
 
No problems.

as a potential enhancement you might consider forcing pagebreaks after a certain number of characters. (you would add some heuristic in to make sure it didn't break in the middle of a word).
 
Yes, that's the problem of automating it in that way. I didn't realise that it's possible to stipulate what the break shouldn't occur around.

The heuristic would have its hands full: the article must be more than so-many characters, then split it at half that number (say), but don't do it for a list, an image, an a href, etc.

I often wonder about ways to do it - the rules would have to be very comprehensive.

All the best
 
i wasn't thinking in terms that complex. i'd guess there is a simpler heuristic which would generally work:

1. find the first <br/> or </p> after a certain number of characters from counter and apply a pagebreak.
2. reset the counter to 0
3. start again.

it's a cludge{kludge?} but I guess you don't need it to be a perfect solution.
 
That's very interesting. Yes, that might work, especially if a category field - back to this again - could say 'y' or 'n', to bring the heuristic into play or not. (But I have to confess that my attempts to get a category field to work don't work.) I'll think about this idea tonight, Justin. Many thanks.
 
when you say category field do you mean a checkbox? sorry if i'm being dim.
 
Sorry, Justin, here I am coming back very late. Yes, I did mean with a checkbox.

What I have found when doing blurbs with just a little of the story (say 60 characters) is that html code gets in the way and wrecks what follows. I suppose one could use a function to strip all that's superfluous away. Yes, that must be the way.

I was using - LEFT(story, 60) in the mysql SELECT query. I've seen the php code that removes html code, but not for mysql. (Which I presume means I should have coded it in the php area not mysql.) I'll have to think this through again. All the best to you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top