Help - Search - Members - Calendar
Full Version: Another Question
Codegrrl.com Forums > Script Help > Tutorial Help
Phenix
I know people are probably tired of my questions so I ask that you just bare with me please. blush.gif Okay so I'm coding the blog, and I'm using the single entry page, which doesn't allow you to view the entry without an ID. I was wondering two things. First I was wondering how, if I am viewing my post in a descending order with the most recent first, do I make sure when visitors click the link to post a comment they see the relevant comments and post? And second, how do I ensure that when people come to my site www.mysite.org // they see the most recent blog first? I hope I'm not too confusing, and any help would be greatly greatly appreciated.

Example:// http://walkinginchrist.org/vintage/practice.php?id=4 // When you click the link to the comments, it shows another post not the one you would be reading.

index.php
CODE
<?php
mysql_connect ('****', '****', '****');
mysql_select_db ('****');

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid ID specified.");
}

$id = (int)$_GET['id'];
$sql = "SELECT * FROM blog WHERE id='$id' LIMIT 1";


$id = (int)$_GET['id'];
$sql = "SELECT * FROM blog ORDER BY timestamp DESC LIMIT 1";

$result = mysql_query($sql) or print ("Can't select entry from table blog.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {

    $date = date("l F d Y g:ia", $row['timestamp']);

    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $listening = stripslashes($row['listening']);
    $reading = stripslashes($row['reading']);
    $quote = stripslashes($row['quote']);

    ?>

<div class="div" id="content">
<table width="370" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td valign="top"><img src="http://www.walkinginchrist.org/vintage/nav/1/images/welcome_avatar.gif" alt="welcome button"></td>
    <td valign="top" class="div"><br>Hello and welcome to Vintage Heart Online-- my online zine. Located here are my personal opinions on various subjects along with poems, short stories and personal graphics.<br><br>
    Please feel free to browse the site, and link me if you wish. Please note that this Zine is not meant to be the ranting's of a Radical Leftist, but the unjudgemental, personal views of myself.<br>
    <br>
    
    <p align="right"><a href="#">What pray tell is a Zine ?</a></p></td>
  </tr>
</table>



   <table width="370" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td class="entryheader"><?php echo $title; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><?php echo $date; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><strong>Currently Reading:</strong> <?php echo $reading; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><strong>Currently Listening To:</strong> <?php echo $listening; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><strong>Quote:</strong> <?php echo $quote; ?></td>
  </tr>
  <tr>
    <td class="entry"><br><?php echo $entry; ?></td>
  </tr>
</table>

<?php

        $result2 = mysql_query ("SELECT id FROM blog_comments WHERE entry='$id'");
        
        

        if ($num_rows > 0) {
            echo "<a href=\"entry.php?id=" . $id . "\">" . $num_rows . " comments</a>";
        }
        else {
            echo "<a href=\"entry.php?id=" . $id . "\">Leave a comment</a>";
        } ?>
    </p>


    <?php
}
?>




entry.php
CODE
<?php
mysql_connect ('****', '****', '****');
mysql_select_db ('****');

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid ID specified.");
}

$id = (int)$_GET['id'];
$sql = "SELECT * FROM blog WHERE id='$id' LIMIT 1";

$result = mysql_query($sql) or print ("Can't select entry from table blog.<br />" . $sql . "<br />" . mysql_error());

while($row = mysql_fetch_array($result)) {

    $date = date("l F d Y g:ia", $row['timestamp']);

    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $listening = stripslashes($row['listening']);
    $reading = stripslashes($row['reading']);
    $quote = stripslashes($row['quote']);

    ?>
    
       <table width="370" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td class="entryheader"><?php echo $title; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><?php echo $date; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><strong>Currently Reading:</strong> <?php echo $reading; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><strong>Currently Listening To:</strong> <?php echo $listening; ?></td>
  </tr>
  <tr>
    <td class="entrysub"><strong>Quote:</strong> <?php echo $quote; ?></td>
  </tr>
  <tr>
    <td class="entry"><br><?php echo $entry; ?></td>
  </tr>
</table>

<br><br><br>




       <?php
    }
$commenttimestamp = strtotime("now");

$sql = "SELECT * FROM blog_comments WHERE comentry='$id' ORDER BY timestamp";
$result = mysql_query ($sql) or print ("Can't select comments from table blog_comments.<br />" . $sql . "<br />" . mysql_error());
?>

<?php
while($row = mysql_fetch_array($result)) {
    $timestamp = date("l F d Y  @ g:ia", $row['timestamp']);?>
    <?php print("<p>" . stripslashes($row['comment']) . "</p>");?>
    <?php printf("<p>Comment by <a href=\"%s\">%s</a> on %s</p>", stripslashes($row['url']), stripslashes($row['name']), $timestamp);
    }
?>

<form method="post" action="process.php">

<p><input type="hidden" name="comentry" id="comentry" value="<?php echo $id; ?>" />
<input type="hidden" name="timestamp" id="timestamp" value="<?php echo $commenttimestamp; ?>">

<strong><label for="name">Name:</label></strong> <input type="text" name="name" id="name" size="25" /><br />
<strong><label for="email">E-mail:</label></strong> <input type="text" name="email" id="email" size="25" /><br />
<strong><label for="url">URL:</label></strong> <input type="text" name="url" id="url" size="25" value="http://" /><br />
<strong><label for="comment">Comment:</label></strong><br />
<textarea cols="25" rows="5" name="comment" id="comment"></textarea></p>

<p><input type="submit" name="submit_comment" id="submit_comment" value="Add Comment" /></p>

</form>
Amelie
The single entry page should automatically show comments for the entry ID. If you go to entry.php?id=4, it should show the comments for entry 4, regardless of how you're sorting the entries on the main page.

I notice though that you seem to have your index page confused with your single entry page... The index page doesn't need an ID. The code at the top should be:

CODE
<?php
mysql_connect ('****', '****', '****');
mysql_select_db ('****');

$sql = "SELECT * FROM blog ORDER BY timestamp DESC LIMIT 1";


Instead of what you have now, which is

CODE
<?php
mysql_connect ('****', '****', '****');
mysql_select_db ('****');

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Invalid ID specified.");
}

$id = (int)$_GET['id'];
$sql = "SELECT * FROM blog WHERE id='$id' LIMIT 1";


$id = (int)$_GET['id'];
$sql = "SELECT * FROM blog ORDER BY timestamp DESC LIMIT 1";


The ID part is only for the single entries page, to show comments for that particular entry. You will still get the latest post on your index page (since you have specified only to show one post on your index page), but you don't need an ID for that. Hope that solves your problem smile.gif
Phenix
That didn't work either, sad.gif It just took me to a blank page. Any ideas?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.