Old 25-11-2004, 13:19   #1 (permalink)
NickToye
Senior Member
 
Join Date: Oct 2004
Location: Chester
Posts: 364
Displaying Total Records

I think I have asked this question before, and I know how to answer it in a certain aspect, but for this aspect I'm a bit confused.

Also believe me I have tried to do it on my own, this is my last resort.

I have a blog page that lists articles from a record set rsArticles.

At the end of each article I have a display record count and this is for the comments that have been made for this particular article. It doesn't seem to work.

PHP Code:
<?php require_once('Connections/connNickToye.php'); ?>
<?php
$maxRows_rsArticles 
5;
$pageNum_rsArticles 0;
if (isset(
$_GET['pageNum_rsArticles'])) {
$pageNum_rsArticles $_GET['pageNum_rsArticles'];
}
$startRow_rsArticles $pageNum_rsArticles $maxRows_rsArticles;
mysql_select_db($database_connNickToye$connNickToye);
$query_rsArticles "SELECT date_format(pub_date, '%D %M %Y') as pub_date, article_id, topic_id, title, text, picture FROM articles ORDER BY pub_date DESC";
$query_limit_rsArticles sprintf("%s LIMIT %d, %d"$query_rsArticles$startRow_rsArticles$maxRows_rsArticles);
$rsArticles mysql_query($query_limit_rsArticles$connNickToye) or die(mysql_error());
$row_rsArticles mysql_fetch_assoc($rsArticles);
if (isset(
$_GET['totalRows_rsArticles'])) {
$totalRows_rsArticles $_GET['totalRows_rsArticles'];
} else {
$all_rsArticles mysql_query($query_rsArticles);
$totalRows_rsArticles mysql_num_rows($all_rsArticles);
}
$totalPages_rsArticles ceil($totalRows_rsArticles/$maxRows_rsArticles)-1;
 
mysql_select_db($database_connNickToye$connNickToye);
$query_rsLinks "SELECT * FROM inspiration ORDER BY title ASC";
$rsLinks mysql_query($query_rsLinks$connNickToye) or die(mysql_error());
$row_rsLinks mysql_fetch_assoc($rsLinks);
$totalRows_rsLinks mysql_num_rows($rsLinks);
mysql_select_db($database_connNickToye$connNickToye);
$query_rsTopics "SELECT * FROM topics";
$rsTopics mysql_query($query_rsTopics$connNickToye) or die(mysql_error());
$row_rsTopics mysql_fetch_assoc($rsTopics);
$totalRows_rsTopics mysql_num_rows($rsTopics);
mysql_select_db($database_connNickToye$connNickToye);
$query_rsArticleDates "SELECT date_format(pub_date, '%Y-%c-%e') as ArticleDate FROM articles";
$rsArticleDates mysql_query($query_rsArticleDates$connNickToye) or die(mysql_error());
$row_rsArticleDates mysql_fetch_assoc($rsArticleDates);
$totalRows_rsArticleDates mysql_num_rows($rsArticleDates);
$colname_rsComments "-1";
if (isset(
$_POST['article_id'])) {
$colname_rsComments = (get_magic_quotes_gpc()) ? $_POST['article_id'] : addslashes($_POST['article_id']);
}
mysql_select_db($database_connNickToye$connNickToye);
$query_rsComments sprintf("SELECT * FROM comments WHERE article_id = %s"$colname_rsComments);
$rsComments mysql_query($query_rsComments$connNickToye) or die(mysql_error());
$row_rsComments mysql_fetch_assoc($rsComments);
$totalRows_rsComments mysql_num_rows($rsComments);
//line break function
function formatParagraphs ($text)
{
$text ereg_replace("\n",'<br />',$text);
return 
$text;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main.dwt.php" codeOutsideHTMLIsLocked="false" --><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Blog</title>
<style type="text/css">
<!--
.style3 {font-size: 14px}
-->
</style>
<!-- InstanceEndEditable --><link href="/css/myStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="inner">
<div id="header"></div>
<!-- InstanceBeginEditable name="nav" -->
<ul id="nav">
     <li id="home"><a href="index.php">HOME </a></li>
     <li id="about"><a href="about.php">ABOUT</a></li>
     <li id="blog"><a href="blog.php" class="active">BLOG</a></li>
     <li id="work"><a href="work.php">WORK</a></li>
     <li id="contact"><a href="contract.php">CONTRACT ME</a></li>
     <li id="admin"><a href="admin/adminIndex.php">ADMIN</a></li>
</ul>
<!-- InstanceEndEditable -->
<div id="content">
<!-- InstanceBeginEditable name="main" -->
<?php do { ?>
        <span class="title"><?php echo $row_rsArticles['title']; ?></span> <br />
        <br />
        <span class="article"><?php echo formatParagraphs($row_rsArticles['text']); ?></span><br />
        <br />
        <br />
        <img src="<?php echo $row_rsArticles['picture']; ?>" alt="article image"> <br />
        <span class="updated"><?php echo $row_rsArticles['pub_date']; ?></span><br />
        <br />
        <span class="viewComment"><a href="viewComments.php?article_id=<?php echo $row_rsArticles['article_id']; ?>">View Comments [<?php echo $totalRows_rsComments ?>]</a></span> <span class="style3">|</span> <a href="addComment.php?article_id=<?php echo $row_rsArticles['article_id']; ?>" class="addComment">Add Comment </a>
        <form name="form1" id="form1" method="post" action="">
         <input name="article_id" type="hidden" id="article_id" value="<?php echo $row_rsArticles['article_id']; ?>" />
        </form>
        <hr size="1" class="linebreak" />
        <?php } while ($row_rsArticles mysql_fetch_assoc($rsArticles)); ?>
<!-- InstanceEndEditable -->
</div> 
<div id="sidebar">
<!-- InstanceBeginEditable name="sidebar" -->
<p class="sidebarHeader">Topics</p>
<ul>
<?php do { ?>
<li><a href="viewArticleByTopic.php?topic_id=<?php echo $row_rsTopics['topic_id']; ?>"><?php echo $row_rsTopics['topic']; ?></a></li>
<?php } while ($row_rsTopics mysql_fetch_assoc($rsTopics)); ?>
</ul>
<p class="sidebarHeader">Archive</p>
<?php 
function build_calendar($month,$year,$day) {
    
/* Declaring the variables */
    
$daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa');
    
$firstDayOfMonth mktime(0,0,0,$month,1,$year);
    
$noDays date('t',$firstDayOfMonth);
    
$dateComponents getdate($firstDayOfMonth);
    
$dayOfWeek $dateComponents['wday'];
    
$monthName date('F',mktime(0,0,0,$month,1,$year));
 
    global 
$_GET;
    global 
$rsArticleDates;
 
    if (
mysql_num_rows($rsArticleDates) > 0){
     
mysql_data_seek($rsArticleDates,0);
     while(
$row_rsArticleDates mysql_fetch_assoc($rsArticleDates)){
     
$dates[] = $row_rsArticleDates['ArticleDate'];
     }
    }
 
    
/* Computing the previous month. */
    
if($month == 1) {
     
$mn=12;
     
$yn=$year-1;
     } else {
     
$mn=$month-1;
     
$yn=$year;
    }
 
    
/* Computing the next month. */
    
if($month == 12) {
     
$mn2=1;
     
$yn2=$year+1;
    } else {
     
$mn2=$month+1;
     
$yn2=$year;
    }
 
    
/* Calendar header: next and previous month links */
    
$calendar "<table>";
    
$calendar .= "<tr><td><a href=\"day.php?m=$mn&amp;y=$yn&amp;d=$day\">&lt;</a></td>";
    
$calendar .="<td colspan=\"5\" align=\"center\">$monthName, $year</td>";
    
$calendar .="<td><a href=\"day.php?m=$mn2&amp;y=$yn2&amp;d=$day\">&gt;</a></td></tr>";
    
$calendar .="<tr>"
 
    
/* Calendar header: Display the days of the week */
    
foreach($daysOfWeek as $day) { 
             
$calendar .= "<td>$day</td>"
    } 
    
$calendar .= "</tr>"
    
$calendar .= "<tr>"
     
$currentDay 1;
 
     
/* Fill in the beginning of the calendar body */    
     
if ($dayOfWeek 0) { 
        
$calendar .= "<td colspan='$dayOfWeek'>&nbsp;</td>"
     } 
 
     
/* Generate the calendar body */ 
     
while ($currentDay <= $noDays) { 
         if (
$dayOfWeek == 7) { 
                 
$dayOfWeek 0
                 
$calendar .= "</tr><tr>"
         } 
     
$date $year."-".$month."-".$currentDay;
     if (
in_array($date,$dates)) { 
     
$calendar .= "<td><a href='day.php?m=$month&amp;y=$year&amp;d=$currentDay'>$currentDay</a></td>"
     } else {
     
$calendar .= "<td>$currentDay</td>";
     }
     
$currentDay++; 
     
$dayOfWeek++; 
     } 
/* Filling in the end of the calendar body */
if ($dayOfWeek != 7) { 
            
$remainingDays $dayOfWeek
            
$calendar .= "<td colspan='$remainingDays'>&nbsp;</td></tr>"

 
     
$calendar .= "</table>"
return 
$calendar;

if (isset(
$_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){ 
$month $_GET['m'];
$year $_GET['y'];
$day $_GET['d'];
} else {
$dateComponents getdate();
$month $dateComponents['mon'];
$year $dateComponents['year'];
$day $dateComponents['mday'];
}
echo 
build_calendar($month,$year,$day);
?>
<p class="sidebarHeader">Inspiration</p>
<ul>
<?php do { ?>
<li><a href="<?php echo $row_rsLinks['link']; ?>"><?php echo $row_rsLinks['title']; ?></a></li>
<?php } while ($row_rsLinks mysql_fetch_assoc($rsLinks)); ?>
</ul>
<!-- InstanceEndEditable -->
</div>
<div class="clearer"></div>
</div>
</div>
<div id="footer"><span class="style2">
Powered By <a href="<A href="http://www.macromedia.com/software/dreamweaver/">Dreamweaver">http://www.macromedia.com/software/dreamweaver/">Dreamweaver MX 2004</a>, <a href="<A href="http://www.mysql.com/">MySQL</a">http://www.mysql.com/">MySQL</a> and <a href="<A href="http://www.php.net/">PHP</a">http://www.php.net/">PHP</a>. 
Copyright Nick Toye 2004<br />
<a href="<A href="http://validator.w3.org/check/referer">XHTML</a">http://validator.w3.org/check/referer">XHTML</a>, <a href="<A href="http://jigsaw.w3.org/css-validator/validator?uri=http://www.nicktoye.co.uk/css/myStyle.css">CSS</a">http://jigsaw.w3.org/css-validator/validator?uri=http://www.nicktoye.co.uk/css/myStyle.css">CSS</a> </span></div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result
($rsArticles);
mysql_free_result($rsTopics);
mysql_free_result($rsArticleDates);
mysql_free_result($rsComments);
mysql_free_result($rsLinks);
?>

If anyone can explain to me what I have done wrong. For all my other pages where I am displaying a single article clicked from a recent articles list, I am passing the URL parameter and it is displaying the correct count.

Many thanks in advance
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8