SitePoint Sponsor |
|
User Tag List
Results 1 to 16 of 16
Thread: splitting up articles
-
Jan 19, 2001, 12:40 #1
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am looking for the code that will allow me to split up my articles into "pages". I have searched the Forums and I can only find incomplete chunks of the code that I want to use. Would someone mind posting the full code itself or a link to the code?
cheersAdobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 12:56 #2
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That is a fairly broad request. How are the articles being stored in the database?
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 13:12 #3
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sorry all. The articles are being stored in a DB in one large field.
id
title
heading (must appear at the top of every page)
body (the actual article)
dateAdobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 13:28 #4
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That will be pretty tough to do, and make it look nice. Maybe if you were to put some sort of delimiter in the article itself where the atricle should be broken like [newpage] to separate the pages, you could take the article split it on [newpage].
if(!isset($page)) $page = 0;
$articletext = explode("[newpage]", $articletext);
print $articletext[$page];
This would print the first page and then you would need links like I showed you before to make the next / prev links
for the next link
if ($page != (count($articletext) - 1)) {
printf('<a href="%s?page=%s">next >></a>', $PHP_SELF, $page + 1);
}
for the prev link
if ($page != 0) {
printf('<a href="%s?page=%s">prev <<</a>', $PHP_SELF, $page - 1);
}
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 13:33 #5
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Freddy...I was planning on having a delimiter in the text. I don't have it yet, but I can set that up no sweat.
SO, I would do my query just like normal and then use the snippet of code you gave me to split it up and print it out?
ok...for somereason I thought there was a lot more to it. What about a custom piece of text for the "next" and "previous" links? I have seen some people askign for that and that sounds like it might be a cool thing.
<Edited by creole on 01-19-2001 at 01:36 PM>Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 13:38 #6
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What exactly do you mean custom piece of text?
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 13:53 #7
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I mean letting me customize what the link will say that's all. Instead of ever page having "next page" and "previous" page, let me define the text say in the article itself.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 14:09 #8
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That will be a little bit trickier since you are not storing chapters you could put a page title in brackets say right after the [newpage]
something like sdljsdfkskdf l;sfjk ;lfsdkg [newpage][How to fly fish]dafjdfj slfjd sf glksflk sfl
Try this
<?
$str = "[First Page]fjkhsfkdjhgskdfj hsfjkhg sfkjhkjsdf hkjsdfhg jkhgs kljhdfzsgjk hdfjkg h[newpage][Page 2]dhfgsdkjf sjkdfhsjkdhf sdjkfh khfkasdjh ksfjahg kjsdfahg sda[newpage][Page 3]sd;fgjsdfl; gjkdf;ljkg l;fdkj lf;xdk fl;skg sl;fk";
if (!isset($page)) $page = 0;
$text = explode("[newpage]", $str);
print substr($text[$page], strpos($text[$page], "]") + 1, strlen($text[$page]));
print '<p><p>';
if ($page != 0) {
printf('<a href="%s?page=%s">%s</a>', $PHP_SELF, $page - 1, substr($text[$page - 1], strpos($text[$page - 1], "[") + 1, strpos($text[$page - 1], "]") - 1));
}
print "<br>";
if ($page != (count($articletext) - 1)) {
printf('<a href="%s?page=%s">%s</a>', $PHP_SELF, $page + 1, substr($text[$page + 1], strpos($text[$page + 1], "[") + 1, strpos($text[$page + 1], "]") - 1));
}
?>
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 14:38 #9
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
by chapters, you mean breaking the story up into "paragraphs"? Well, I am not doing that because the storyies for the most part are only about 2 pages long. I will put the [newpage] breaks about every 3-4 paragraphs.
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 14:41 #10
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
NO I am just saying that you could put whatever you want the links to say in brackets right after [newpage] like I have in my example, it doesn't ahve to mean chapters just a label for the links. Does that make sense?
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 14:57 #11
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yes
Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 15:04 #12
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
So then what is your question exactly?
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 18:26 #13
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thats what i did:
I have:
[PAGEBREAK] which splits up the page, then after a page break, anything before the first: | is considered a title and anything after the first: | is a chapter. After the second | is the content.
It works great for me....
Peter
-
Jan 19, 2001, 19:02 #14
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well...for right now, I will forgo having titles as I didn't quite understand the code there...
This is the winner for me...
while ($row = mysql_fetch_array($result)) {
echo $row["heading"];
if(!isset($page)) {
$page = 0;
} else {
$page = $page;
}
$articletext = explode("[newpage]", $row["body"]);
print $articletext[$page];
echo "<br><br>";
}
print "<div align=\"center\">";
// for the prev link
if ($page != 0) {
printf('<a href="show_news.php3?id=%s&page=%s" class="mainpage"><<<Previous Page</a> ', $id, $page - 1);
}
// for the next link
if ($page != (count($articletext) - 1)) {
printf('<a href="show_news.php3?id=%s&page=%s" class="mainpage">Next Page>>></a>', $id, $page + 1);
}
print "</div>";Adobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
-
Jan 19, 2001, 19:10 #15
- Join Date
- Aug 2000
- Location
- San Diego, CA
- Posts
- 5,460
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just a small tip Andy you don't need to assign $page to $page like below if page isn't set then it gets set to 0 if it is set then you don't need to reassign it.
if(!isset($page)) {
$page = 0;
} else {
$page = $page;
}
This can be written as
if(!isset($page)) {
$page = 0;
}
Or for efficiency's sake
if(!isset($page)) $page = 0;
What part about the other code do you not understand basically after you split the page up you will have a certian number of elements in the array $articletext
if each element started with [some link text] then the text you could take whatever was in those brackets and put it in the link and then just print out the rest of the text
Please don't PM me with questions.
Use the forums, that is what they are here for.
-
Jan 19, 2001, 19:21 #16
- Join Date
- Oct 2000
- Location
- Nashvegas Baby!
- Posts
- 7,845
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'll give it a try a bit later...right now I have my hands full just breaking the articles down into bite size chunks.
thanks again Freddy...
I think that I am going to have put that line into my signature...lolAdobe Certified Coldfusion MX 7 Developer
Adobe Certified Advanced Coldfusion MX Developer
My Blog (new) | My Family | My Freelance | My Recipes
Bookmarks