我正在使用 SQL 数据库在 Dreamweaver 中创建一个个人博客,并且我已经设置了记录集导航以“翻转”SQL 数据库中的所有博客文章。问题是我在 SQL 数据库中有大约 84 篇博客文章,但其中只有 15 篇可以通过记录集导航访问。我将如何使它能够“翻阅”SQL 数据库中的所有博客文章。
这是页面的代码;
<?php require_once('Connections/blog.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_blog, $blog);
$query_getArchives = "SELECT DISTINCT DATE_FORMAT(news.updated, '%M %Y') AS archive, DATE_FORMAT(news.updated, '%Y-%m') AS link FROM news ORDER BY news.updated DESC";
$getArchives = mysql_query($query_getArchives, $blog) or die(mysql_error());
$row_getArchives = mysql_fetch_assoc($getArchives);
$totalRows_getArchives = mysql_num_rows($getArchives);
mysql_select_db($database_blog, $blog);
$query_getRecent = "SELECT news.post_id, news.title FROM news ORDER BY news.updated DESC LIMIT 10";
$getRecent = mysql_query($query_getRecent, $blog) or die(mysql_error());
$row_getRecent = mysql_fetch_assoc($getRecent);
$totalRows_getRecent = mysql_num_rows($getRecent);
$maxRows_getDisplay = 10;
$pageNum_getDisplay = 0;
if (isset($_GET['pageNum_getDisplay'])) {
$pageNum_getDisplay = $_GET['pageNum_getDisplay'];
}
$startRow_getDisplay = $pageNum_getDisplay * $maxRows_getDisplay;
mysql_select_db($database_blog, $blog);
$query_getDisplay = "SELECT news.title, news.pre, DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC";
$query_limit_getDisplay = sprintf("%s LIMIT %d, %d", $query_getDisplay, $startRow_getDisplay, $maxRows_getDisplay);
$getDisplay = mysql_query($query_limit_getDisplay, $blog) or die(mysql_error());
$row_getDisplay = mysql_fetch_assoc($getDisplay);
if (isset($_GET['totalRows_getDisplay'])) {
$totalRows_getDisplay = $_GET['totalRows_getDisplay'];
} else {
$all_getDisplay = mysql_query($query_getDisplay);
$totalRows_getDisplay = mysql_num_rows($all_getDisplay);
}
$totalPages_getDisplay = ceil($totalRows_getDisplay/$maxRows_getDisplay)-1;
$queryString_getDisplay = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_getDisplay") == false &&
stristr($param, "totalRows_getDisplay") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_getDisplay = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_getDisplay = sprintf("&totalRows_getDisplay=%d%s", $totalRows_getDisplay, $queryString_getDisplay);
$var1_getDisplay2 = "-1";
if (isset($_GET['archive'])) {
$var1_getDisplay2 = $_GET['archive'];
$query_getDisplay = sprintf("SELECT news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE DATE_FORMAT(news.updated, '%%Y-%%m') = %s ORDER BY news.updated DESC", GetSQLValueString($var1_getDisplay2, "text"));
} elseif (isset($_GET['post_id'])) {
$var2_getDisplay3 = $_GET['post_id'];
$query_getDisplay = sprintf("SELECT news.title, news.blog_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE news.post_id = %s", GetSQLValueString($var2_getDisplay3, "int"));
} else {
$query_getDisplay = "SELECT news.title, news.blog_entry, DATE_FORMAT(news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC LIMIT ".$pageNum_getDisplay.", 5";
}
$getDisplay = mysql_query($query_getDisplay, $blog) or die(mysql_error());
$row_getDisplay = mysql_fetch_assoc($getDisplay);
$totalRows_getDisplay = mysql_num_rows($getDisplay);
?>
<!doctype html>
<!--[if lt IE 7]> <html class="ie6 oldie"> <![endif]-->
<!--[if IE 7]> <html class="ie7 oldie"> <![endif]-->
<!--[if IE 8]> <html class="ie8 oldie"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home - Robdogga55's Paradise</title>
<link href="styles/boilerplate.css" rel="stylesheet" type="text/css">
<link href="styles/blog.css" rel="stylesheet" type="text/css">
<style type="text/css">
body,td,th {
font-size: 14px;
}
</style>
<!--
To learn more about the conditional comments around the html tags at the top of the file:
paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
Do the following if you're using your customized build of modernizr (http://www.modernizr.com/):
* insert the link to your js here
* remove the link below to the html5shiv
* add the "no-js" class to the html tags at the top
* you can also remove the link to respond.min.js if you included the MQ Polyfill in your modernizr build
-->
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="styles/respond.min.js"></script>
<script type="text/javascript">
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_blog_entryloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_blog_entryloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
</script>
</head>
<body onLoad="MM_blog_entryloadImages('/test/images/buttons/readmore2.gif')">
<div id="LayoutDiv3">
<?php include 'header.php'; ?>
<div id="about_box">
G'day,</p>
<p style="text-align: left;">I'm Rob, now you might be asking who is this kid? Just some noob looking for attention? No I am a teen who lives in Australia.</p>
<p style="text-align: left;">This is my personal blog, but I also use to to promote my videos on YouTube and to tell people about my public Minecraft server. <br /><div align="center"><a href="/blog_test/about.php"><img id="readmore" src="images/buttons/readmore.gif"></a></div></p>
</div>
<div id="recent">
<h3>Recent Posts</h3>
<ul>
<?php do { ?>
<li><a href="post.php?post_id=<?php echo $row_getRecent['post_id']; ?>"><?php echo $row_getRecent['title']; ?></a></li>
<?php } while ($row_getRecent = mysql_fetch_assoc($getRecent)); ?>
</ul>
<h3>Archives</h3>
<ul>
<?php do { ?>
<li><a href="archive.php?archive=<?php echo $row_getArchives['link']; ?>"><?php echo $row_getArchives['archive']; ?></a></li>
<?php } while ($row_getArchives = mysql_fetch_assoc($getArchives)); ?>
</ul>
<br />
</div>
<?php do { ?>
<div id="blog_posts_container">
<h3><?php echo $row_getDisplay['title']; ?></h3>
<p class="update">Posted on <?php echo $row_getDisplay['formatted']; ?></p>
<div class="blog_entry" id="blog_posts">
<p><?php echo nl2br($row_getDisplay['blog_entry']); ?></p>
</div></div>
<?php } while ($row_getDisplay = mysql_fetch_assoc($getDisplay)); ?>
<div id="blog_posts_container">
<table border="0">
<tr>
<td><?php if ($pageNum_getDisplay > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, 0, $queryString_getDisplay); ?>">First</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_getDisplay > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, max(0, $pageNum_getDisplay - 5), $queryString_getDisplay); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_getDisplay < $totalPages_getDisplay) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, min($totalPages_getDisplay, $pageNum_getDisplay + 5), $queryString_getDisplay); ?>">Next</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_getDisplay < $totalPages_getDisplay) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_getDisplay=%d%s", $currentPage, $totalPages_getDisplay, $queryString_getDisplay); ?>">Last</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</body>
</div>
</html>
<?php
mysql_free_result($getArchives);
mysql_free_result($getRecent);
mysql_free_result($getDisplay);
?>
谢谢,如果你能提供帮助,我已经为此烦恼了很久。:)