I have been trying to figure out this same problem. I did get it to "sort of" work (PHP + MySQL), but in a different way. You can see it by clicking on one of the test articles/tutorials here. I racked my brian trying to figure out a way similar to the way that you mention since it would seem to allow for better database design, but I came up with nothing. I am still pretty new to PHP and MqSQL so take all of this with a grain of salt. This is what I came up with thus far...
I have a form in the admin area of my site. Included in the form are 8 HTML textareas. Each textarea represents a page of the article/tutorial.
when the data is sent to the database, the data from the first textarea is placed in the articles table in a column named "thearticle", the second textarea is also placed in the articles table but in its own column: "pg2", third textarea goes to "pg3" column, forth textarea goes to "pg4" column, and so on. Don't let the column name "thearticle" confuse you. I named it before adding the other pages. It should probably be renamed to "pg1". Just haven't bothered yet. At any rate, the pages are broken up before going into the database.
This set up has some issues of couse. Remember, I am new and tyring to solve this problem, so it is by no means the finalized/correct way... just some playing around with ideas.
One issue is that if an article/tutorial has only one page (which would go into "thearticle" column), then pg2, pg3, pg4, pg5, pg6, pg7, and pg8 columns would be empty in the table. Probably not the best database design.
I am currently working on a layout for the database to make it 2NF (second normal form) compliant. I'm not sure if making this database 2NF compliant is even possible or if it would make it all okay, but I'm tying to figure that out. Google, learn. Google, learn. Google, learn... its an endless process.
Another issue is that the articles/tutorials would be limited to 8 pages. I suppose there could be more, but agian I'm not sure about a clean database design using this method.
The PHP file that I use to display the article and the "prev 1 2 3 next" links is brought to a given page via PHP's "include" function. With "if" statements and the such, it is coded so that an article with 5 total pages will have the links displayed as "prev 1 2 3 4 5 next"... an article with 8 pages will display the links as "prev 1 2 3 4 5 6 7 8 next". You get the idea.
Here is the code of the included file:
//create connection
//require from outside public_html for security $conn is connect variable.
require_once('../PATH/FILE.php');
//select database
$db = mysql_select_db ("DATABASE");
//create sql statement
$sql = "SELECT * FROM articles WHERE id='$id'";
//execute sql query and get result
$sql_result = mysql_query($sql) or die(mysql_error());
if (!$sql_result) {
echo '<p>Sorry, there has been a system error in retrieving the data. Please contact us at <a href="mailto:EMAIL@EMAIL.com">EMAIL@EMAIL.com</a> if this persists.</p>';
} else {
$content = mysql_fetch_array($sql_result);
//converts MySql date to format:Month XXrd, YEAR
$date = date("F jS, Y", strtotime($content[date]));
echo "<p><span class=\"articleHeader\">$content[title]</span><br />\n";
echo "<span class=\"xofx\">Added on: $date</span></p>\n";
//if there is more than one page (if page 2 exists) build prev, next, and page links
if ($content[pg2]) {
//set default links to the $pageX variables for the links
$page1 = "<a href=\"$letter.php?id=$content[id]&row=pg1\">1</a>\n";
$page2 = "<a href=\"$letter.php?id=$content[id]&row=pg2\">2</a>\n";
$page3 = "<a href=\"$letter.php?id=$content[id]&row=pg3\">3</a>\n";
$page4 = "<a href=\"$letter.php?id=$content[id]&row=pg4\">4</a>\n";
$page5 = "<a href=\"$letter.php?id=$content[id]&row=pg5\">5</a>\n";
$page6 = "<a href=\"$letter.php?id=$content[id]&row=pg6\">6</a>\n";
$page7 = "<a href=\"$letter.php?id=$content[id]&row=pg7\">7</a>\n";
$page8 = "<a href=\"$letter.php?id=$content[id]&row=pg8\">8</a>\n";
//if clicked page X echo page X and set prev and next and dead link for page X
if ($row == 'pg1') {
echo "$content[thearticle]\n";
$prev = "<span class=\"PNdead\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</span>\n";
$next = "<a href=\"$letter.php?id=$content[id]&row=pg2\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
$page1 = "<span class=\"PNdead\">1</span>\n";
} elseif ($row == 'pg2') {
//if there is no next page make next link dead or esle make it live
if (!$content[pg3]) {
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
} else {
$next = "<a href=\"$letter.php?id=$content[id]&row=pg3\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
}
echo "$content[pg2]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg1\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$page2 = "<span class=\"PNdead\">2</span>\n";
} elseif ($row == 'pg3') {
//if there is no next page make next link dead or esle make it live
if (!$content[pg4]) {
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
} else {
$next = "<a href=\"$letter.php?id=$content[id]&row=pg4\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
}
echo "$content[pg3]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg2\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$page3 = "<span class=\"PNdead\">3</span>\n";
} elseif ($row == 'pg4') {
//if there is no next page make next link dead or esle make it live
if (!$content[pg5]) {
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
} else {
$next = "<a href=\"$letter.php?id=$content[id]&row=pg5\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
}
echo "$content[pg4]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg3\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$page4 = "<span class=\"PNdead\">4</span>\n";
} elseif ($row == 'pg5') {
//if there is no next page make next link dead or esle make it live
if (!$content[pg6]) {
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
} else {
$next = "<a href=\"$letter.php?id=$content[id]&row=pg6\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
}
echo "$content[pg5]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg4\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$page5 = "<span class=\"PNdead\">5</span>\n";
} elseif ($row == 'pg6') {
//if there is no next page make next link dead or esle make it live
if (!$content[pg7]) {
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
} else {
$next = "<a href=\"$letter.php?id=$content[id]&row=pg7\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
}
echo "$content[pg6]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg5\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$page6 = "<span class=\"PNdead\">6</span>\n";
} elseif ($row == 'pg7') {
//if there is no next page make next link dead or esle make it live
if (!$content[pg8]) {
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
} else {
$next = "<a href=\"$letter.php?id=$content[id]&row=pg8\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></a>\n";
}
echo "$content[pg7]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg6\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$page7 = "<span class=\"PNdead\">7</span>\n";
} elseif ($row == 'pg8') {
echo "$content[pg8]";
$prev = "<a href=\"$letter.php?id=$content[id]&row=pg7\"><img id=\"arowLeft\" src=\"images/arrowLeft.gif\" alt=\"\" />Prev</a>\n";
$next = "<span class=\"PNdead\">Next<img id=\"arrowRight\" src=\"images/arrowRight.gif\" alt=\"\" /></span>\n";
$page8 = "<span class=\"PNdead\">8</span>\n";
}
echo "<p id=\"page\">\n";
echo "<span id=\"numbers\">\n";
echo $prev;
echo $page1;
echo $page2;
//if there is a page X then echo the link
if ($content[pg3]) {
echo $page3;
}
if ($content[pg4]) {
echo $page4;
}
if ($content[pg5]) {
echo $page5;
}
if ($content[pg6]) {
echo $page6;
}
if ($content[pg7]) {
echo $page7;
}
if ($content[pg8]) {
echo $page8;
}
echo $next;
echo "</span>\n";
echo "</p>\n";
} else {
echo "$content[thearticle]\n";
}
}
mysql_close();
The $letter variable is not set in the above code, but in the page that includes the above php code (via PHP "include" function).
Hope this helps your venture at least a small bit Don.
I would love to hear other solutions or how to make the database 2NF compliant. Thanks!