Home arrow ASP arrow Page 5 - Building a Multi-Page Article System With ASP/PHP
ASP

Building a Multi-Page Article System With ASP/PHP


Interested in building your own CMS? In this article Mitchell shows us how to build a multi-page article system that can be used in any web-based CMS...

Author Info:
By: Mitchell Harper
Rating: 4 stars4 stars4 stars4 stars4 stars / 35
January 05, 2003
TABLE OF CONTENTS:
  1. · Building a Multi-Page Article System With ASP/PHP
  2. · How Everything Will Work
  3. · The JavaScript Behind it All
  4. · Saving Articles to the Database
  5. · Displaying a List of Articles
  6. · Conclusion

print this article
SEARCH DEVARTICLES

Building a Multi-Page Article System With ASP/PHP - Displaying a List of Articles
(Page 5 of 6 )

It's very easy to display a list of articles from the articles table in our database. We simply loop through the articles table and output the title and summary for each article. We also setup a link to read the entire article, which we will look at shortly. Shown below is the code for both ASP and PHP:

ASP Code

<!-- #INCLUDE file="db.asp" -->
<%

objRS.Open "select * from articles order by articleId asc"

while not objRS.EOF
%>
<font face="Verdana" size="4"><b><%=objRS("title")%></b></font><br><br>
<font face="Verdana" size="2">
<%=objRS("summary")%><br><br>
<a href="fullarticle.asp?articleId=<%=objRS("articleId")%>">Read More...</a>
</font>
<hr><br>
<%
objRS.MoveNext
wend

%>


PHP Code

include("db.php");

$result = mysql_query("select * from articles order by articleId asc");

while($row = mysql_fetch_array($result))
{
?>
<font face="Verdana" size="4"><b><?php echo $row["title"]; ?></b></font><br><br>
<font face="Verdana" size="2">
<?php echo $row["summary"]; ?><br><br>
<a href="fullarticle.asp?articleId=<?php echo $row["articleId"]; ?>">Read More...</a>
</font>
<hr><br>
<?php
}


Here's the output from the code above:

The output from the showarticles.php page

Displaying an Individual Article
To display an individual article, we simply list the pages in that article as links and start by displaying the title and content of the first page:

ASP Code

<!-- #INCLUDE file="db.asp" -->
<%

articleId = Request.QueryString("articleId")
pageId = Request.QueryString("pageId")

if not isNumeric(articleId) then
Response.Write "Invalid article Id"
Response.End
end if

if pageId = "" then
objRS.Open("select top 1 pageId from pages where articleId=" & articleId)
pageId = objRS("pageId")
end if

if objRS.State = 1 then objRS.Close
objRS.Open("select * from articles inner join pages on articles.articleId = pages.articleId where articles.articleId = " & articleId & " and pages.pageId = " & pageId)

if objRS.EOF then
Response.Write "Article not found"
Response.End
end if

%>
<html>
<head>
<title>Multi-Page Article System</title>
</head>

<body bgcolor="#ffffff">
<font face="Verdana" size="5"><b><%=objRS.Fields(1)%></b></font><br><br>
<font face="Verdana" size="3"><b><i><%=objRS.Fields(6)%></i></b></font><br>
<font face="Verdana" size="2"><%=objRS.Fields(7)%></font><br><br>
<font face="Verdana" size="1">
Article Pages:
<%

'Display the pages in this article
if objRS.State = 1 then objRS.Close
objRS.Open("select * from pages where articleId = " & articleId)

while not objRS.EOF
if CStr(objRS("pageId")) = CStr(pageId) then
Response.Write "<li><b>" & objRS("title") & "</b></li>"
else
Response.Write "<li><a href='fullarticle.asp?articleId=" & articleId & "&pageId=" & objRS("pageId") & "'>" & objRS("title") & "</a></li>"
end if

objRS.MoveNext
wend

%>
</font>
</body>
</html>


PHP Code

<?php

include("db.php");

$articleId = @$_GET["articleId"];
$pageId = @$_GET["pageId"];

if(!is_numeric($articleId))
{
die("Invalid article Id");
}

if($pageId == "")
{
$result = mysql_query("select pageId from pages where articleId=" . $articleId . " limit 1");
$row = mysql_fetch_array($result);
$pageId = $row["pageId"];
}

$result = mysql_query("select * from articles inner join pages on articles.articleId = pages.articleId where articles.articleId = " . $articleId . " and pages.pageId = " . $pageId);

if(mysql_num_rows($result) == 0)
{
die("Article not found");
}

$row = mysql_fetch_array($result);

?>
<html>
<head>
<title>Multi-Page Article System</title>
</head>

<body bgcolor="#ffffff">
<font face="Verdana" size="5"><b><?php echo $row[1];?></b></font><br><br>
<font face="Verdana" size="3"><b><i><?php echo $row[6];?></i></b></font><br>
<font face="Verdana" size="2"><?php echo $row[7];?></font><br><br>
<font face="Verdana" size="1">
Article Pages:
<?php

//Display the pages in this article
$result = mysql_query("select * from pages where articleId = " . $articleId);

while($row = mysql_fetch_array($result))
{
if($pageId == $row["pageId"])
echo "<li><b>" . $row["title"] . "</b></li>";
else
echo "<li><a href='fullarticle.php?articleId=" . $articleId . "&pageId=" . $row["pageId"] . "'>" . $row["title"] . "</a></li>";
}

?>
</font>
</body>
</html>


And the result? Well, take a look:

The fullarticle.php page
blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials